X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_AISObject.cpp;h=2365746655bf4d095c096c00aae855a4a703e0ad;hb=3afc257344780d0447d4fca3f26c91d932d0a0b0;hp=de00d5a436b33a88144ec9e07bca6a0b11ce77f5;hpb=758a57d77b6fa3a0485fa3378a1280c7e87a74aa;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index de00d5a43..236574665 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: GeomAPI_AISObject.cpp // Created: 25 Jun 2014 // Author: Artem ZHIDKOV @@ -15,32 +17,42 @@ #include #include #include +#include #include +#include #include #include #include #include #include #include +#include + +#include const double tolerance = 1e-7; const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance -// Initialization of color constants -int Colors::COLOR_BROWN = Quantity_NOC_BROWN; -int Colors::COLOR_RED = Quantity_NOC_RED; -int Colors::COLOR_GREEN = Quantity_NOC_GREEN; -int Colors::COLOR_BLUE = Quantity_NOC_BLUE1; - GeomAPI_AISObject::GeomAPI_AISObject() : GeomAPI_Interface(new Handle(AIS_InteractiveObject)()) { } -void GeomAPI_AISObject::createShape(boost::shared_ptr theShape) +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 = (theShape && theShape->implPtr()) ? @@ -63,10 +75,10 @@ void GeomAPI_AISObject::createShape(boost::shared_ptr theShape) setImpl(new Handle(AIS_InteractiveObject)(new AIS_Shape(aTDS))); } -void GeomAPI_AISObject::createDistance(boost::shared_ptr theStartPoint, - boost::shared_ptr theEndPoint, - boost::shared_ptr theFlyoutPoint, - boost::shared_ptr thePlane, double theDistance) +void GeomAPI_AISObject::createDistance(std::shared_ptr theStartPoint, + std::shared_ptr theEndPoint, + std::shared_ptr theFlyoutPoint, + std::shared_ptr thePlane, double theDistance) { double aFlyout = 0; if (theFlyoutPoint) { @@ -74,15 +86,15 @@ void GeomAPI_AISObject::createDistance(boost::shared_ptr theStartPo if (theStartPoint->distance(theEndPoint) < tolerance) aDist = theStartPoint->distance(theFlyoutPoint); else { - boost::shared_ptr aLine = boost::shared_ptr( + std::shared_ptr aLine = std::shared_ptr( new GeomAPI_Lin(theStartPoint, theEndPoint)); aDist = aLine->distance(theFlyoutPoint); } - boost::shared_ptr aLineDir = theEndPoint->xyz()->decreased(theStartPoint->xyz()); - boost::shared_ptr aFOutDir = theFlyoutPoint->xyz()->decreased( + std::shared_ptr aLineDir = theEndPoint->xyz()->decreased(theStartPoint->xyz()); + std::shared_ptr aFOutDir = theFlyoutPoint->xyz()->decreased( theStartPoint->xyz()); - boost::shared_ptr aNorm = thePlane->direction()->xyz(); + std::shared_ptr aNorm = thePlane->direction()->xyz(); if (aLineDir->cross(aFOutDir)->dot(aNorm) < 0) aDist = -aDist; aFlyout = aDist; @@ -97,9 +109,9 @@ void GeomAPI_AISObject::createDistance(boost::shared_ptr theStartPo 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); @@ -121,11 +133,11 @@ void GeomAPI_AISObject::createDistance(boost::shared_ptr theStartPo } } -void GeomAPI_AISObject::createRadius(boost::shared_ptr theCircle, - boost::shared_ptr theFlyoutPoint, +void GeomAPI_AISObject::createRadius(std::shared_ptr theCircle, + std::shared_ptr theFlyoutPoint, double theRadius) { - boost::shared_ptr aCenter = theCircle->center(); + std::shared_ptr aCenter = theCircle->center(); // TODO: a bug in AIS_RadiusDimension: // The anchor point can't be myCirc.Location() - an exception is raised. @@ -133,10 +145,10 @@ void GeomAPI_AISObject::createRadius(boost::shared_ptr theCircle, // We want to show a radius dimension starting from the circle centre and // ending at the user-defined point. // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all. - boost::shared_ptr anAnchor = theCircle->project(theFlyoutPoint); - boost::shared_ptr anAnchorXYZ = anAnchor->xyz(); + std::shared_ptr anAnchor = theCircle->project(theFlyoutPoint); + std::shared_ptr anAnchorXYZ = anAnchor->xyz(); anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz()); - boost::shared_ptr aDeltaDir(new GeomAPI_Dir(anAnchorXYZ)); + std::shared_ptr aDeltaDir(new GeomAPI_Dir(anAnchorXYZ)); const double aDelta = 1e-3; anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x()); anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y()); @@ -170,10 +182,10 @@ void GeomAPI_AISObject::createRadius(boost::shared_ptr theCircle, } } -void GeomAPI_AISObject::createParallel(boost::shared_ptr theLine1, - boost::shared_ptr theLine2, - boost::shared_ptr theFlyoutPoint, - boost::shared_ptr thePlane) +void GeomAPI_AISObject::createParallel(std::shared_ptr theLine1, + std::shared_ptr theLine2, + std::shared_ptr theFlyoutPoint, + std::shared_ptr thePlane) { Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); Handle(AIS_InteractiveObject) anAIS = impl(); @@ -197,9 +209,9 @@ void GeomAPI_AISObject::createParallel(boost::shared_ptr theLine1 } } -void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr theLine1, - boost::shared_ptr theLine2, - boost::shared_ptr thePlane) +void GeomAPI_AISObject::createPerpendicular(std::shared_ptr theLine1, + std::shared_ptr theLine2, + std::shared_ptr thePlane) { Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); Handle(AIS_InteractiveObject) anAIS = impl(); @@ -221,29 +233,39 @@ void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr the } -void GeomAPI_AISObject::createFixed(boost::shared_ptr theShape, - boost::shared_ptr thePlane) +void GeomAPI_AISObject::createFixed(std::shared_ptr theShape, + std::shared_ptr thePlane) { Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); Handle(AIS_InteractiveObject) anAIS = impl(); + TopoDS_Shape aShape = theShape->impl(); + Handle(AIS_FixRelation) aFixPrs; if (anAIS.IsNull()) { - Handle(AIS_FixRelation) aFixPrs = - new AIS_FixRelation(theShape->impl(), aPlane); + aFixPrs = new AIS_FixRelation(aShape, aPlane); setImpl(new Handle(AIS_InteractiveObject)(aFixPrs)); } else { - Handle(AIS_PerpendicularRelation) aFixPrs = - Handle(AIS_PerpendicularRelation)::DownCast(anAIS); + aFixPrs = Handle(AIS_FixRelation)::DownCast(anAIS); if (!aFixPrs.IsNull()) { - aFixPrs->SetFirstShape(theShape->impl()); + aFixPrs->SetFirstShape(aShape); aFixPrs->SetPlane(aPlane); aFixPrs->Redisplay(Standard_True); } } + if (!aFixPrs.IsNull()) { + Bnd_Box aBox; + BRepBndLib::Add(aShape, aBox); + double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax; + aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + gp_Pnt aXYZ1(aXmin, aXmax, aYmin); + gp_Pnt aXYZ2(aXmax, aYmax, aZmax); + double aDist = aXYZ1.Distance(aXYZ2); + if (aDist > Precision::Confusion()) { + aFixPrs->SetArrowSize(aDist/8.); + } + } } - - void GeomAPI_AISObject::setColor(const int& theColor) { Handle(AIS_InteractiveObject) anAIS = impl(); @@ -255,27 +277,54 @@ void GeomAPI_AISObject::setColor(const int& theColor) 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); + 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); + Quantity_Color aCurrentColor; + anAIS->Color(aCurrentColor); + // do not set the same color to the presentation + if (aColor.IsEqual(aCurrentColor)) + return false; + 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); + 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 @@ -287,3 +336,74 @@ bool GeomAPI_AISObject::empty() const return false; } +int GeomAPI_AISObject::getShapeType() const +{ + Handle(AIS_InteractiveObject) anAIS = const_cast(this) + ->impl(); + if (!anAIS.IsNull()) { + Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!aAISShape.IsNull()) { + return aAISShape->Shape().ShapeType(); + } + } + return -1; +} + +void GeomAPI_AISObject::setPointMarker(int theType, double theScale) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes(); + if (aDrawer->HasOwnPointAspect()) { + Handle(Prs3d_PointAspect) aPA = aDrawer->PointAspect(); + aPA->SetTypeOfMarker((Aspect_TypeOfMarker)theType); + aPA->SetScale(theScale); + } else { + Quantity_NameOfColor aCol = Quantity_NOC_YELLOW; + aDrawer->SetPointAspect(new Prs3d_PointAspect((Aspect_TypeOfMarker)theType, aCol, theScale)); + } + } +} + +bool GeomAPI_AISObject::setLineStyle(int theStyle) +{ + bool isChanged = false; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + 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; +} + +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()) { + double aCurrentValue = anAIS->Transparency(); + isChanged = aCurrentValue != theVal; + if (isChanged) + aContext->SetTransparency(anAIS, theVal, false); + } + } + return isChanged; +}