File indexing completed on 2025-01-18 10:02:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _AIS_ColorScale_HeaderFile
0016 #define _AIS_ColorScale_HeaderFile
0017
0018 #include <AIS_InteractiveObject.hxx>
0019 #include <Aspect_TypeOfColorScaleData.hxx>
0020 #include <Aspect_TypeOfColorScalePosition.hxx>
0021 #include <Aspect_SequenceOfColor.hxx>
0022 #include <Standard.hxx>
0023 #include <Standard_DefineHandle.hxx>
0024 #include <TCollection_ExtendedString.hxx>
0025 #include <TColStd_SequenceOfExtendedString.hxx>
0026
0027 class AIS_ColorScale;
0028 DEFINE_STANDARD_HANDLE(AIS_ColorScale, AIS_InteractiveObject)
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 class AIS_ColorScale : public AIS_InteractiveObject
0039 {
0040 DEFINE_STANDARD_RTTIEXT(AIS_ColorScale, AIS_InteractiveObject)
0041 public:
0042
0043
0044 Standard_EXPORT static Standard_Boolean FindColor (const Standard_Real theValue,
0045 const Standard_Real theMin,
0046 const Standard_Real theMax,
0047 const Standard_Integer theColorsCount,
0048 const Graphic3d_Vec3d& theColorHlsMin,
0049 const Graphic3d_Vec3d& theColorHlsMax,
0050 Quantity_Color& theColor);
0051
0052
0053 static Standard_Boolean FindColor (const Standard_Real theValue,
0054 const Standard_Real theMin,
0055 const Standard_Real theMax,
0056 const Standard_Integer theColorsCount,
0057 Quantity_Color& theColor)
0058 {
0059 return FindColor (theValue, theMin, theMax, theColorsCount,
0060 Graphic3d_Vec3d (230.0, 1.0, 1.0),
0061 Graphic3d_Vec3d (0.0, 1.0, 1.0),
0062 theColor);
0063 }
0064
0065
0066
0067
0068 static Standard_Real hueToValidRange (const Standard_Real theHue)
0069 {
0070 Standard_Real aHue = theHue;
0071 while (aHue < 0.0) { aHue += 360.0; }
0072 while (aHue > 360.0) { aHue -= 360.0; }
0073 return aHue;
0074 }
0075
0076 public:
0077
0078
0079 Standard_EXPORT AIS_ColorScale();
0080
0081
0082 Standard_EXPORT Standard_Boolean FindColor (const Standard_Real theValue, Quantity_Color& theColor) const;
0083
0084
0085 Standard_Real GetMin() const { return myMin; }
0086
0087
0088 void SetMin (const Standard_Real theMin) { SetRange (theMin, GetMax()); }
0089
0090
0091 Standard_Real GetMax() const { return myMax; }
0092
0093
0094 void SetMax (const Standard_Real theMax) { SetRange (GetMin(), theMax); }
0095
0096
0097 void GetRange (Standard_Real& theMin, Standard_Real& theMax) const
0098 {
0099 theMin = myMin;
0100 theMax = myMax;
0101 }
0102
0103
0104
0105
0106 Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
0107
0108
0109 Standard_Real HueMin() const { return myColorHlsMin[0]; }
0110
0111
0112 Standard_Real HueMax() const { return myColorHlsMax[0]; }
0113
0114
0115 void HueRange (Standard_Real& theMinAngle,
0116 Standard_Real& theMaxAngle) const
0117 {
0118 theMinAngle = myColorHlsMin[0];
0119 theMaxAngle = myColorHlsMax[0];
0120 }
0121
0122
0123
0124 void SetHueRange (const Standard_Real theMinAngle,
0125 const Standard_Real theMaxAngle)
0126 {
0127 myColorHlsMin[0] = theMinAngle;
0128 myColorHlsMax[0] = theMaxAngle;
0129 }
0130
0131
0132 void ColorRange (Quantity_Color& theMinColor,
0133 Quantity_Color& theMaxColor) const
0134 {
0135 theMinColor.SetValues (hueToValidRange (myColorHlsMin[0]), myColorHlsMin[1], myColorHlsMin[2], Quantity_TOC_HLS);
0136 theMaxColor.SetValues (hueToValidRange (myColorHlsMax[0]), myColorHlsMax[1], myColorHlsMax[2], Quantity_TOC_HLS);
0137 }
0138
0139
0140 void SetColorRange (const Quantity_Color& theMinColor,
0141 const Quantity_Color& theMaxColor)
0142 {
0143 theMinColor.Values (myColorHlsMin[0], myColorHlsMin[1], myColorHlsMin[2], Quantity_TOC_HLS);
0144 theMaxColor.Values (myColorHlsMax[0], myColorHlsMax[1], myColorHlsMax[2], Quantity_TOC_HLS);
0145 }
0146
0147
0148
0149
0150 Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; }
0151
0152
0153
0154
0155 void SetLabelType (const Aspect_TypeOfColorScaleData theType) { myLabelType = theType; }
0156
0157
0158
0159
0160 Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; }
0161
0162
0163
0164
0165 void SetColorType (const Aspect_TypeOfColorScaleData theType) { myColorType = theType; }
0166
0167
0168 Standard_Integer GetNumberOfIntervals() const { return myNbIntervals; }
0169
0170
0171 Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
0172
0173
0174 const TCollection_ExtendedString& GetTitle() const { return myTitle; }
0175
0176
0177 void SetTitle (const TCollection_ExtendedString& theTitle) { myTitle = theTitle; }
0178
0179
0180
0181
0182 const TCollection_AsciiString& GetFormat() const { return myFormat; }
0183
0184
0185 const TCollection_AsciiString& Format() const { return myFormat; }
0186
0187
0188 void SetFormat (const TCollection_AsciiString& theFormat) { myFormat = theFormat; }
0189
0190
0191
0192
0193
0194 Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const;
0195
0196
0197
0198 Standard_EXPORT Quantity_Color GetIntervalColor (const Standard_Integer theIndex) const;
0199
0200
0201
0202
0203
0204
0205 Standard_EXPORT void SetIntervalColor (const Quantity_Color& theColor, const Standard_Integer theIndex);
0206
0207
0208 Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
0209
0210
0211 const TColStd_SequenceOfExtendedString& Labels() const { return myLabels; }
0212
0213
0214
0215
0216
0217
0218
0219 Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
0220
0221
0222 Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
0223
0224
0225 const Aspect_SequenceOfColor& GetColors() const { return myColors; }
0226
0227
0228
0229 Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
0230
0231
0232
0233
0234
0235 void SetUniformColors (Standard_Real theLightness,
0236 Standard_Real theHueFrom, Standard_Real theHueTo)
0237 {
0238 SetColors (MakeUniformColors (myNbIntervals, theLightness, theHueFrom, theHueTo));
0239 SetColorType (Aspect_TOCSD_USER);
0240 }
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257 Standard_EXPORT static Aspect_SequenceOfColor
0258 MakeUniformColors (Standard_Integer theNbColors, Standard_Real theLightness,
0259 Standard_Real theHueFrom, Standard_Real theHueTo);
0260
0261
0262 Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
0263
0264
0265 void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos) { myLabelPos = thePos; }
0266
0267
0268 Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
0269
0270
0271 Standard_DEPRECATED("AIS_ColorScale::SetTitlePosition() has no effect!")
0272 void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos) { myTitlePos = thePos; }
0273
0274
0275
0276
0277 Standard_Boolean IsReversed() const { return myIsReversed; }
0278
0279
0280 void SetReversed (const Standard_Boolean theReverse) { myIsReversed = theReverse; }
0281
0282
0283
0284 Standard_Boolean IsSmoothTransition() const { return myIsSmooth; }
0285
0286
0287 void SetSmoothTransition (const Standard_Boolean theIsSmooth) { myIsSmooth = theIsSmooth; }
0288
0289
0290
0291
0292
0293 Standard_Boolean IsLabelAtBorder() const { return myIsLabelAtBorder; }
0294
0295
0296
0297 void SetLabelAtBorder (const Standard_Boolean theOn) { myIsLabelAtBorder = theOn; }
0298
0299
0300 Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
0301
0302
0303 void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; }
0304
0305
0306
0307
0308
0309
0310 Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer theIndex);
0311
0312
0313
0314 void GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const
0315 {
0316 theBreadth = myBreadth;
0317 theHeight = myHeight;
0318 }
0319
0320
0321 void SetSize (const Standard_Integer theBreadth, const Standard_Integer theHeight)
0322 {
0323 myBreadth = theBreadth;
0324 myHeight = theHeight;
0325 }
0326
0327
0328
0329 Standard_Integer GetBreadth() const { return myBreadth; }
0330
0331
0332 void SetBreadth (const Standard_Integer theBreadth) { myBreadth = theBreadth; }
0333
0334
0335
0336 Standard_Integer GetHeight() const { return myHeight; }
0337
0338
0339 void SetHeight (const Standard_Integer theHeight) { myHeight = theHeight; }
0340
0341
0342 void GetPosition (Standard_Real& theX, Standard_Real& theY) const
0343 {
0344 theX = myXPos;
0345 theY = myYPos;
0346 }
0347
0348
0349 void SetPosition (const Standard_Integer theX, const Standard_Integer theY)
0350 {
0351 myXPos = theX;
0352 myYPos = theY;
0353 }
0354
0355
0356 Standard_Integer GetXPosition() const { return myXPos; }
0357
0358
0359 void SetXPosition (const Standard_Integer theX) { myXPos = theX; }
0360
0361
0362 Standard_Integer GetYPosition() const { return myYPos; }
0363
0364
0365 void SetYPosition (const Standard_Integer theY) { myYPos = theY; }
0366
0367
0368 Standard_Integer GetTextHeight() const { return myTextHeight; }
0369
0370
0371 void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
0372
0373 public:
0374
0375
0376
0377 Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
0378
0379
0380
0381 Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
0382
0383 Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText,
0384 const Standard_Integer theHeight,
0385 Standard_Integer& theWidth,
0386 Standard_Integer& theAscent,
0387 Standard_Integer& theDescent) const;
0388
0389 public:
0390
0391
0392 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
0393
0394
0395 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0396 const Handle(Prs3d_Presentation)& thePresentation,
0397 const Standard_Integer theMode) Standard_OVERRIDE;
0398
0399
0400 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& ,
0401 const Standard_Integer ) Standard_OVERRIDE {}
0402
0403 private:
0404
0405
0406
0407
0408 void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
0409
0410
0411 Standard_Real GetIntervalValue (const Standard_Integer theIndex) const;
0412
0413
0414
0415
0416
0417 Quantity_Color colorFromValue (const Standard_Real theValue,
0418 const Standard_Real theMin,
0419 const Standard_Real theMax) const;
0420
0421
0422 void updateTextAspect();
0423
0424
0425
0426
0427
0428
0429
0430 void drawText (const Handle(Graphic3d_Group)& theGroup,
0431 const TCollection_ExtendedString& theText,
0432 const Standard_Integer theX, const Standard_Integer theY,
0433 const Graphic3d_VerticalTextAlignment theVertAlignment);
0434
0435
0436 Standard_Integer computeMaxLabelWidth (const TColStd_SequenceOfExtendedString& theLabels) const;
0437
0438
0439 void drawLabels (const Handle(Graphic3d_Group)& theGroup,
0440 const TColStd_SequenceOfExtendedString& theLabels,
0441 const Standard_Integer theBarBottom,
0442 const Standard_Integer theBarHeight,
0443 const Standard_Integer theMaxLabelWidth,
0444 const Standard_Integer theColorBreadth);
0445
0446
0447 void drawColorBar (const Handle(Prs3d_Presentation)& thePrs,
0448 const Standard_Integer theBarBottom,
0449 const Standard_Integer theBarHeight,
0450 const Standard_Integer theMaxLabelWidth,
0451 const Standard_Integer theColorBreadth);
0452
0453
0454
0455
0456
0457
0458
0459 void drawFrame (const Handle(Prs3d_Presentation)& thePrs,
0460 const Standard_Integer theX, const Standard_Integer theY,
0461 const Standard_Integer theWidth, const Standard_Integer theHeight,
0462 const Quantity_Color& theColor);
0463
0464 private:
0465
0466 Standard_Real myMin;
0467 Standard_Real myMax;
0468 Graphic3d_Vec3d myColorHlsMin;
0469 Graphic3d_Vec3d myColorHlsMax;
0470 TCollection_ExtendedString myTitle;
0471 TCollection_AsciiString myFormat;
0472 Standard_Integer myNbIntervals;
0473 Aspect_TypeOfColorScaleData myColorType;
0474 Aspect_TypeOfColorScaleData myLabelType;
0475 Standard_Boolean myIsLabelAtBorder;
0476 Standard_Boolean myIsReversed;
0477 Standard_Boolean myIsLogarithmic;
0478 Standard_Boolean myIsSmooth;
0479 Aspect_SequenceOfColor myColors;
0480 TColStd_SequenceOfExtendedString myLabels;
0481 Aspect_TypeOfColorScalePosition myLabelPos;
0482 Aspect_TypeOfColorScalePosition myTitlePos;
0483 Standard_Integer myXPos;
0484 Standard_Integer myYPos;
0485 Standard_Integer myBreadth;
0486 Standard_Integer myHeight;
0487 Standard_Integer mySpacing;
0488 Standard_Integer myTextHeight;
0489
0490 };
0491
0492 #endif