X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_AISObject.cpp;h=30879add3d8743dd85afcbcfbe43b979a5ef439d;hb=283433d9c2f39fbd332d6eba691b6a0cd875e29d;hp=6be05290b1d06ac86d6ad5cc2c7f8c252ea6cc94;hpb=75d7f663c7784d1d5a516c7fe97cfedbfa5fdb1b;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 6be05290b..30879add3 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -29,6 +29,8 @@ #include #include +#include + const double tolerance = 1e-7; const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint @@ -39,6 +41,17 @@ GeomAPI_AISObject::GeomAPI_AISObject() { } +GeomAPI_AISObject::~GeomAPI_AISObject() +{ + if (!empty()) { + // This is necessary for correct deletion of Handle entity. + // Without this Handle does not decremented counter to 0 + Handle(AIS_InteractiveObject) *anAIS = implPtr(); + anAIS->Nullify(); + } +} + + void GeomAPI_AISObject::createShape(std::shared_ptr theShape) { const TopoDS_Shape& aTDS = @@ -58,8 +71,16 @@ void GeomAPI_AISObject::createShape(std::shared_ptr theShape) aShapeAIS->Set(aTDS); aShapeAIS->Redisplay(Standard_True); } - } else - setImpl(new Handle(AIS_InteractiveObject)(new AIS_Shape(aTDS))); + } else { + // Set default point as a '+' symbol + Handle(AIS_Shape) aShape = new AIS_Shape(aTDS); + Handle(Prs3d_Drawer) aDrawer = aShape->Attributes(); + if (aDrawer->HasOwnPointAspect()) + aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS); + else + aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.)); + setImpl(new Handle(AIS_InteractiveObject)(aShape)); + } } void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoint, @@ -96,9 +117,9 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoin Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); anAspect->MakeArrows3d(Standard_False); - anAspect->MakeText3d(false); + anAspect->MakeText3d(Standard_False); anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); - anAspect->MakeTextShaded(false); + anAspect->MakeTextShaded(Standard_True); anAspect->ArrowAspect()->SetLength(theDistance / 10.); aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); aDimAIS->SetDimensionAspect(anAspect); @@ -253,41 +274,63 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr theShape, } } - - void GeomAPI_AISObject::setColor(const int& theColor) { Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) return; Quantity_Color aColor((Quantity_NameOfColor) theColor); - anAIS->SetColor(aColor); Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); } + Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); + aContext->SetColor(anAIS, aColor, false); } -void GeomAPI_AISObject::setWidth(const double& theWidth) +bool GeomAPI_AISObject::setWidth(const double& theWidth) { + bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); - if (anAIS.IsNull()) - return; - anAIS->SetWidth(theWidth); - anAIS->Redisplay(); + if (!anAIS.IsNull()) { + isChanged = anAIS->Width() != theWidth; + if (isChanged) + anAIS->SetWidth(theWidth); + } + return isChanged; } -void GeomAPI_AISObject::setColor(int theR, int theG, int theB) +bool GeomAPI_AISObject::setColor(int theR, int theG, int theB) { Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) - return; + return false; Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB); - anAIS->SetColor(aColor); + Quantity_Color aCurrentColor; + anAIS->Color(aCurrentColor); + // do not set the same color to the presentation + if (aColor.IsEqual(aCurrentColor)) + return false; + Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); } + Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); + aContext->SetColor(anAIS, aColor, false); + return true; +} + +void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (anAIS.IsNull()) + return; + + Quantity_Color aColor = anAIS->Color(); + theR = (int)(aColor.Red()*255.); + theG = (int)(aColor.Green()*255.); + theB = (int)(aColor.Blue()*255.); } bool GeomAPI_AISObject::empty() const @@ -306,7 +349,9 @@ int GeomAPI_AISObject::getShapeType() const if (!anAIS.IsNull()) { Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anAIS); if (!aAISShape.IsNull()) { - return aAISShape->Shape().ShapeType(); + const TopoDS_Shape aShape = aAISShape->Shape(); + if (!aShape.IsNull()) + return aShape.ShapeType(); } } return -1; @@ -316,8 +361,8 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale) { Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { - Handle(AIS_Drawer) aDrawer = anAIS->Attributes(); - if (aDrawer->HasPointAspect()) { + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + if (aDrawer->HasOwnPointAspect()) { Handle(Prs3d_PointAspect) aPA = aDrawer->PointAspect(); aPA->SetTypeOfMarker((Aspect_TypeOfMarker)theType); aPA->SetScale(theScale); @@ -328,26 +373,47 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale) } } - -void GeomAPI_AISObject::setLineStyle(int theStyle) +bool GeomAPI_AISObject::setLineStyle(int theStyle) { + bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { - Handle(AIS_Drawer) aDrawer = anAIS->Attributes(); - if (aDrawer->HasLineAspect()) - aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle); - if (aDrawer->HasWireAspect()) - aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle); + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + Handle(Prs3d_LineAspect) aLineAspect; + + Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle; + if (aDrawer->HasOwnLineAspect()) { + aLineAspect = aDrawer->LineAspect(); + } + if (aDrawer->HasOwnWireAspect()) { + aLineAspect = aDrawer->WireAspect(); + } + Quantity_Color aCurrentColor; + Aspect_TypeOfLine aCurrentType; + Standard_Real aCurrentWidth; + aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth); + isChanged = aType != aCurrentType; + if (isChanged) { + aLineAspect->SetTypeOfLine(aType); + } } + return isChanged; } - -void GeomAPI_AISObject::setTransparensy(double theVal) +bool GeomAPI_AISObject::setTransparensy(double theVal) { + bool isChanged = false; Handle(AIS_InteractiveObject) anAIS = impl(); if (!anAIS.IsNull()) { Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - if (!aContext.IsNull()) - aContext->SetTransparency(anAIS, theVal, false); + if (!aContext.IsNull()) { + double aCurrentValue = anAIS->Transparency(); + isChanged = aCurrentValue != theVal; + if (isChanged) + aContext->SetTransparency(anAIS, theVal, false); + } else { + anAIS->SetTransparency(theVal); + } } + return isChanged; }