X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_AISObject.cpp;h=3f7646688b80eab7f6c9736522d5c8b05eec0de3;hb=b9a93c1ac199671649cf2371dfe9fda2bbe65fd0;hp=021ebfeb2cce4dcd5a3e9c854b121f4910974ae6;hpb=31e91a8d11e03ddce87e8c2aa04695961a266a97;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 021ebfeb2..3f7646688 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,32 @@ 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)); + } +} + +std::shared_ptr GeomAPI_AISObject::getShape() const +{ + std::shared_ptr aResult; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); + if (aShapeAIS) { + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(aShapeAIS->Shape())); + return aResult; + } + } + return std::shared_ptr(); } void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoint, @@ -120,6 +157,21 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoin } } +bool GeomAPI_AISObject::isEmptyDistanceGeometry() +{ + bool anEmpty = false; + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + anEmpty = !aDimAIS->IsValid(); + } + } + + return anEmpty; +} + void GeomAPI_AISObject::createRadius(std::shared_ptr theCircle, std::shared_ptr theFlyoutPoint, double theRadius) @@ -253,23 +305,12 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr theShape, } } -void GeomAPI_AISObject::redisplay() -{ - Handle(AIS_InteractiveObject) anAIS = impl(); - if (!anAIS.IsNull()) { - Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); - aContext->Redisplay(anAIS, false); - } -} - - 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); @@ -278,28 +319,59 @@ void GeomAPI_AISObject::setColor(const int& theColor) aContext->SetColor(anAIS, aColor, false); } -void GeomAPI_AISObject::setWidth(const double& theWidth) +double GeomAPI_AISObject::width() { + double aWidth = 0.0; Handle(AIS_InteractiveObject) anAIS = impl(); - if (anAIS.IsNull()) - return; - anAIS->SetWidth(theWidth); - anAIS->Redisplay(); + if (!anAIS.IsNull()) { + aWidth = anAIS->Width(); + } + return aWidth; +} + +bool GeomAPI_AISObject::setWidth(const double& theWidth) +{ + bool isChanged = false; + Handle(AIS_InteractiveObject) anAIS = impl(); + 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 @@ -318,7 +390,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; @@ -328,8 +402,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); @@ -340,26 +414,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; }