X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_AISObject.cpp;h=021ebfeb2cce4dcd5a3e9c854b121f4910974ae6;hb=31e91a8d11e03ddce87e8c2aa04695961a266a97;hp=b2bb96faf0dcb7b2cb81c7fd7ebf3505cdec6fa9;hpb=0c10db12692c21f2ce38b9eebd27981a8eee6b41;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index b2bb96faf..021ebfeb2 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,41 +17,38 @@ #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; - +const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint +const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance GeomAPI_AISObject::GeomAPI_AISObject() - : GeomAPI_Interface(new Handle(AIS_InteractiveObject)()) + : GeomAPI_Interface(new Handle(AIS_InteractiveObject)()) { } -void GeomAPI_AISObject::createShape(boost::shared_ptr theShape) +void GeomAPI_AISObject::createShape(std::shared_ptr theShape) { - const TopoDS_Shape& aTDS = (theShape && theShape->implPtr()) ? - theShape->impl() : TopoDS_Shape(); + const TopoDS_Shape& aTDS = + (theShape && theShape->implPtr()) ? + theShape->impl() : TopoDS_Shape(); Handle(AIS_InteractiveObject) anAIS = impl(); - if (!anAIS.IsNull()) - { + if (!anAIS.IsNull()) { Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); - if (aShapeAIS) - { + if (aShapeAIS) { // if the AIS object is displayed in the opened local context in some mode, additional // AIS sub objects are created there. They should be rebuild for correct selecting. // It is possible to correct it by closing local context before the shape set and opening @@ -59,57 +58,59 @@ void GeomAPI_AISObject::createShape(boost::shared_ptr theShape) aShapeAIS->Set(aTDS); aShapeAIS->Redisplay(Standard_True); } - } - else + } else 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) - { - boost::shared_ptr aLine = - boost::shared_ptr(new GeomAPI_Lin(theStartPoint, theEndPoint)); - double aDist = aLine->distance(theFlyoutPoint); - - boost::shared_ptr aLineDir = theEndPoint->xyz()->decreased(theStartPoint->xyz()); - boost::shared_ptr aFOutDir = theFlyoutPoint->xyz()->decreased(theStartPoint->xyz()); - boost::shared_ptr aNorm = thePlane->direction()->xyz(); + if (theFlyoutPoint) { + double aDist = 0.0; + if (theStartPoint->distance(theEndPoint) < tolerance) + aDist = theStartPoint->distance(theFlyoutPoint); + else { + std::shared_ptr aLine = std::shared_ptr( + new GeomAPI_Lin(theStartPoint, theEndPoint)); + aDist = aLine->distance(theFlyoutPoint); + } + + std::shared_ptr aLineDir = theEndPoint->xyz()->decreased(theStartPoint->xyz()); + std::shared_ptr aFOutDir = theFlyoutPoint->xyz()->decreased( + theStartPoint->xyz()); + std::shared_ptr aNorm = thePlane->direction()->xyz(); if (aLineDir->cross(aFOutDir)->dot(aNorm) < 0) aDist = -aDist; aFlyout = aDist; } Handle(AIS_InteractiveObject) anAIS = impl(); - if (anAIS.IsNull()) - { - Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension( - theStartPoint->impl(), theEndPoint->impl(), thePlane->impl()); + if (anAIS.IsNull()) { + Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(theStartPoint->impl(), + theEndPoint->impl(), + thePlane->impl()); aDimAIS->SetCustomValue(theDistance); Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d (Standard_False); - anAspect->MakeText3d(false); + anAspect->MakeArrows3d(Standard_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); aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); aDimAIS->SetFlyout(aFlyout); setImpl(new Handle(AIS_InteractiveObject)(aDimAIS)); - } - else { + } else { // update presentation Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { - aDimAIS->SetMeasuredGeometry(theStartPoint->impl(), theEndPoint->impl(), + aDimAIS->SetMeasuredGeometry(theStartPoint->impl(), theEndPoint->impl(), thePlane->impl()); aDimAIS->SetCustomValue(theDistance); aDimAIS->SetFlyout(aFlyout); @@ -119,11 +120,11 @@ void GeomAPI_AISObject::createDistance(boost::shared_ptr theStartPo } } -void GeomAPI_AISObject::createRadius(boost::shared_ptr theCircle, - boost::shared_ptr theFlyoutPoint, - double theRadius) +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. @@ -131,39 +132,36 @@ 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()); anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z()); Handle(AIS_InteractiveObject) anAIS = impl(); - if (anAIS.IsNull()) - { - Handle(AIS_RadiusDimension) aDimAIS = - new AIS_RadiusDimension(theCircle->impl(), anAnchor->impl()); + if (anAIS.IsNull()) { + Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(theCircle->impl(), + anAnchor->impl()); aDimAIS->SetCustomValue(theRadius); Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d (Standard_False); + anAspect->MakeArrows3d(Standard_False); anAspect->MakeText3d(false); anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); + anAspect->ArrowAspect()->SetLength(theRadius / 5.); anAspect->MakeTextShaded(false); aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); - aDimAIS->SetDimensionAspect (anAspect); + aDimAIS->SetDimensionAspect(anAspect); aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); setImpl(new Handle(AIS_InteractiveObject)(aDimAIS)); - } - else - { + } else { // update presentation Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS); - if (!aDimAIS.IsNull()) - { + if (!aDimAIS.IsNull()) { aDimAIS->SetMeasuredGeometry(theCircle->impl(), anAnchor->impl()); aDimAIS->SetCustomValue(theRadius); aDimAIS->Redisplay(Standard_True); @@ -171,27 +169,23 @@ 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(); - if (anAIS.IsNull()) - { - Handle(AIS_ParallelRelation) aParallel = - new AIS_ParallelRelation(theLine1->impl(), theLine2->impl(), aPlane); + if (anAIS.IsNull()) { + Handle(AIS_ParallelRelation) aParallel = new AIS_ParallelRelation( + theLine1->impl(), theLine2->impl(), aPlane); if (theFlyoutPoint) aParallel->SetPosition(theFlyoutPoint->impl()); setImpl(new Handle(AIS_InteractiveObject)(aParallel)); - } - else - { + } else { Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS); - if (!aParallel.IsNull()) - { + if (!aParallel.IsNull()) { aParallel->SetFirstShape(theLine1->impl()); aParallel->SetSecondShape(theLine2->impl()); aParallel->SetPlane(aPlane); @@ -202,24 +196,21 @@ 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(); - if (anAIS.IsNull()) - { - Handle(AIS_PerpendicularRelation) aPerpendicular = - new AIS_PerpendicularRelation(theLine1->impl(), theLine2->impl(), aPlane); + if (anAIS.IsNull()) { + Handle(AIS_PerpendicularRelation) aPerpendicular = new AIS_PerpendicularRelation( + theLine1->impl(), theLine2->impl(), aPlane); setImpl(new Handle(AIS_InteractiveObject)(aPerpendicular)); - } - else - { - Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS); - if (!aPerpendicular.IsNull()) - { + } else { + Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast( + anAIS); + if (!aPerpendicular.IsNull()) { aPerpendicular->SetFirstShape(theLine1->impl()); aPerpendicular->SetSecondShape(theLine2->impl()); aPerpendicular->SetPlane(aPlane); @@ -229,28 +220,146 @@ void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr the } +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()) { + aFixPrs = new AIS_FixRelation(aShape, aPlane); + + setImpl(new Handle(AIS_InteractiveObject)(aFixPrs)); + } else { + aFixPrs = Handle(AIS_FixRelation)::DownCast(anAIS); + if (!aFixPrs.IsNull()) { + 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::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 ; - anAIS->SetColor(Quantity_Color((Quantity_NameOfColor)theColor)); + 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) { Handle(AIS_InteractiveObject) anAIS = impl(); if (anAIS.IsNull()) - return ; + return; anAIS->SetWidth(theWidth); + anAIS->Redisplay(); +} + +void GeomAPI_AISObject::setColor(int theR, int theG, int theB) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (anAIS.IsNull()) + return; + Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB); + 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); } bool GeomAPI_AISObject::empty() const { - Handle(AIS_InteractiveObject) anAIS = - const_cast(this)->impl(); + Handle(AIS_InteractiveObject) anAIS = const_cast(this) + ->impl(); if (anAIS.IsNull()) return true; 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(AIS_Drawer) aDrawer = anAIS->Attributes(); + if (aDrawer->HasPointAspect()) { + 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)); + } + } +} + + +void GeomAPI_AISObject::setLineStyle(int theStyle) +{ + 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); + } +} + + +void GeomAPI_AISObject::setTransparensy(double theVal) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); + if (!aContext.IsNull()) + aContext->SetTransparency(anAIS, theVal, false); + } +}