From 6b437d84d92c29ba8c2c843735fa2feb4f0664c7 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 30 Jun 2014 10:11:32 +0400 Subject: [PATCH] Changes in the presentations of features --- src/GeomAPI/CMakeLists.txt | 4 +- src/GeomAPI/GeomAPI_AISObject.cpp | 253 ++++++++++++++++++ src/GeomAPI/GeomAPI_AISObject.h | 92 +++++++ src/GeomAPI/GeomAPI_Circ.cpp | 10 + src/GeomAPI/GeomAPI_Circ.h | 6 + src/GeomAPI/GeomAPI_Circ2d.cpp | 11 + src/GeomAPI/GeomAPI_Circ2d.h | 6 + src/GeomAPI/GeomAPI_Interface.h | 2 +- src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp | 18 +- src/PartSet/PartSet_Module.cpp | 7 +- src/PartSet/PartSet_TestOCC.cpp | 15 +- src/SketchPlugin/CMakeLists.txt | 5 +- src/SketchPlugin/SketchPlugin_Arc.cpp | 10 +- src/SketchPlugin/SketchPlugin_Arc.h | 4 + src/SketchPlugin/SketchPlugin_Circle.cpp | 6 + src/SketchPlugin/SketchPlugin_Circle.h | 4 + src/SketchPlugin/SketchPlugin_Constraint.cpp | 5 +- src/SketchPlugin/SketchPlugin_Constraint.h | 6 +- .../SketchPlugin_ConstraintDistance.cpp | 60 +---- .../SketchPlugin_ConstraintDistance.h | 3 +- .../SketchPlugin_ConstraintLength.cpp | 95 ++----- .../SketchPlugin_ConstraintLength.h | 3 +- .../SketchPlugin_ConstraintParallel.cpp | 44 +-- .../SketchPlugin_ConstraintParallel.h | 3 +- .../SketchPlugin_ConstraintPerpendicular.cpp | 44 +-- .../SketchPlugin_ConstraintPerpendicular.h | 3 +- .../SketchPlugin_ConstraintRadius.cpp | 87 ++---- .../SketchPlugin_ConstraintRadius.h | 3 +- src/SketchPlugin/SketchPlugin_Feature.cpp | 34 +-- src/SketchPlugin/SketchPlugin_Feature.h | 7 +- src/SketchPlugin/SketchPlugin_Line.cpp | 9 +- src/SketchPlugin/SketchPlugin_Line.h | 4 + src/SketchPlugin/SketchPlugin_Point.cpp | 6 + src/SketchPlugin/SketchPlugin_Point.h | 4 + src/SketchPlugin/SketchPlugin_Sketch.cpp | 21 +- src/SketchPlugin/SketchPlugin_Sketch.h | 5 +- src/XGUI/XGUI_Displayer.cpp | 75 ++++-- src/XGUI/XGUI_Displayer.h | 13 +- 38 files changed, 619 insertions(+), 368 deletions(-) create mode 100644 src/GeomAPI/GeomAPI_AISObject.cpp create mode 100644 src/GeomAPI/GeomAPI_AISObject.h diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 28187984c..e4bd74bf9 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -18,6 +18,7 @@ SET(PROJECT_HEADERS GeomAPI_Dir2d.h GeomAPI_Pln.h GeomAPI_Shape.h + GeomAPI_AISObject.h ) SET(PROJECT_SOURCES @@ -34,6 +35,7 @@ SET(PROJECT_SOURCES GeomAPI_Dir2d.cpp GeomAPI_Pln.cpp GeomAPI_Shape.cpp + GeomAPI_AISObject.cpp ) ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS}) @@ -48,7 +50,7 @@ INCLUDE_DIRECTORIES( ${CAS_INCLUDE_DIRS} ) -TARGET_LINK_LIBRARIES(GeomAPI ${PROJECT_LIBRARIES} ${CAS_KERNEL} ${CAS_MODELER}) +TARGET_LINK_LIBRARIES(GeomAPI ${PROJECT_LIBRARIES} ${CAS_KERNEL} ${CAS_MODELER} ${CAS_VIEWER}) SET(SWIG_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/GeomAPI.py diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp new file mode 100644 index 000000000..5ed7c01d1 --- /dev/null +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -0,0 +1,253 @@ +// File: GeomAPI_AISObject.cpp +// Created: 25 Jun 2014 +// Author: Artem ZHIDKOV + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +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; + + +GeomAPI_AISObject::GeomAPI_AISObject() + : GeomAPI_Interface(new Handle(AIS_InteractiveObject)()) +{ +} + +void GeomAPI_AISObject::createShape(boost::shared_ptr theShape) +{ + const TopoDS_Shape& aTDS = (theShape && theShape->implPtr()) ? + theShape->impl() : TopoDS_Shape(); + + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) + { + Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); + 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 + // after. Another workaround to thrown down the selection and reselecting the AIS. + // If there was a problem here, try the first solution with close/open local context. + + aShapeAIS->Set(aTDS); + aShapeAIS->Redisplay(Standard_True); + } + } + 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) +{ + 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 (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()); + aDimAIS->SetCustomValue(theDistance); + + Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); + anAspect->MakeArrows3d (Standard_False); + anAspect->MakeText3d(false); + anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); + anAspect->MakeTextShaded(false); + aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); + aDimAIS->SetDimensionAspect(anAspect); + aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); + aDimAIS->SetFlyout(aFlyout); + + setImpl(new Handle(AIS_InteractiveObject)(aDimAIS)); + } + else { + // update presentation + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + aDimAIS->SetMeasuredGeometry(theStartPoint->impl(), theEndPoint->impl(), + thePlane->impl()); + aDimAIS->SetCustomValue(theDistance); + aDimAIS->SetFlyout(aFlyout); + + aDimAIS->Redisplay(Standard_True); + } + } +} + +void GeomAPI_AISObject::createRadius(boost::shared_ptr theCircle, + boost::shared_ptr theFlyoutPoint, + double theRadius) +{ + boost::shared_ptr aCenter = theCircle->center(); + + // TODO: a bug in AIS_RadiusDimension: + // The anchor point can't be myCirc.Location() - an exception is raised. + // But we need exactly this case... + // 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(); + anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz()); + boost::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()); + aDimAIS->SetCustomValue(theRadius); + + Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); + anAspect->MakeArrows3d (Standard_False); + anAspect->MakeText3d(false); + anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); + anAspect->MakeTextShaded(false); + aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); + aDimAIS->SetDimensionAspect (anAspect); + aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); + + setImpl(new Handle(AIS_InteractiveObject)(aDimAIS)); + } + else + { + // update presentation + Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) + { + aDimAIS->SetMeasuredGeometry(theCircle->impl(), anAnchor->impl()); + aDimAIS->SetCustomValue(theRadius); + aDimAIS->Redisplay(Standard_True); + } + } +} + +void GeomAPI_AISObject::createParallel(boost::shared_ptr theLine1, + boost::shared_ptr theLine2, + boost::shared_ptr theFlyoutPoint, + boost::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 (theFlyoutPoint) + aParallel->SetPosition(theFlyoutPoint->impl()); + + setImpl(new Handle(AIS_InteractiveObject)(aParallel)); + } + else + { + Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS); + if (!aParallel.IsNull()) + { + aParallel->SetFirstShape(theLine1->impl()); + aParallel->SetSecondShape(theLine2->impl()); + aParallel->SetPlane(aPlane); + if (theFlyoutPoint) + aParallel->SetPosition(theFlyoutPoint->impl()); + aParallel->Redisplay(Standard_True); + } + } +} + +void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr theLine1, + boost::shared_ptr theLine2, + boost::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); + + setImpl(new Handle(AIS_InteractiveObject)(aPerpendicular)); + } + else + { + Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS); + if (!aPerpendicular.IsNull()) + { + aPerpendicular->SetFirstShape(theLine1->impl()); + aPerpendicular->SetSecondShape(theLine2->impl()); + aPerpendicular->SetPlane(aPlane); + aPerpendicular->Redisplay(Standard_True); + } + } +} + + +void GeomAPI_AISObject::setColor(const int& theColor) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (anAIS.IsNull()) + return ; + anAIS->SetColor(Quantity_Color((Quantity_NameOfColor)theColor)); +} + +void GeomAPI_AISObject::setWidth(const double& theWidth) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (anAIS.IsNull()) + return ; + anAIS->SetWidth(theWidth); +} + +bool GeomAPI_AISObject::empty() const +{ + Handle(AIS_InteractiveObject) anAIS = + const_cast(this)->impl(); + if (anAIS.IsNull()) + return true; + return false; +} + diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h new file mode 100644 index 000000000..d3f238591 --- /dev/null +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -0,0 +1,92 @@ +// File: GeomAPI_AISObject.hxx +// Created: 25 Jun 2014 +// Author: Artem ZHIDKOV + +#ifndef GeomAPI_AISObject_HeaderFile +#define GeomAPI_AISObject_HeaderFile + +#include + +#include + +class GeomAPI_Circ; +class GeomAPI_Lin; +class GeomAPI_Pln; +class GeomAPI_Pnt; +class GeomAPI_Shape; + +struct GEOMAPI_EXPORT Colors +{ + static int COLOR_BROWN; +}; + +/** \class GeomAPI_AISObject + * \ingroup DataModel + * \brief Interface for AIS_InteractiveObject + */ + +class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface +{ +public: + /// \brief Creation of empty AIS object + GeomAPI_AISObject(); + + /// \brief Creates AIS_Shape object using specified shape + void createShape(boost::shared_ptr theShape); + + /** \brief Creates AIS_LengthDimension object + * \param[in] theStartPoint first point for dimension + * \param[in] theEndPoint second point for dimension + * \param[in] theFlyoutPoint the flyout of dimension relative to the measured line + * \param[in] thePlane the plane which contains all points above + * \param[in] theDistance value of the distance to be shown + */ + void createDistance(boost::shared_ptr theStartPoint, + boost::shared_ptr theEndPoint, + boost::shared_ptr theFlyoutPoint, + boost::shared_ptr thePlane, + double theDistance); + + /** \brief Creates AIS_RadiusDimension object + * \param[in] theCircle the radius is created for this circle + * \param[in] theFlyoutPoint the flyout of dimension + * \param[in] theRadius value of the radius to be shown + */ + void createRadius(boost::shared_ptr theCircle, + boost::shared_ptr theFlyoutPoint, + double theRadius); + + /** \brief Creates AIS_ParallelRelation object for two lines + * \param[in] theLine1 first parallel line + * \param[in] theLine2 second parallel line + * \param[in] theFlyoutPoint the flyout point for relation + * \param[in] thePlane the plane which contains the lines + */ + void createParallel(boost::shared_ptr theLine1, + boost::shared_ptr theLine2, + boost::shared_ptr theFlyoutPoint, + boost::shared_ptr thePlane); + + /** \brief Creates AIS_PerpendicularRelation object for two lines + * \param[in] theLine1 first parallel line + * \param[in] theLine2 second parallel line + * \param[in] thePlane the plane which contains the lines + */ + void createPerpendicular(boost::shared_ptr theLine1, + boost::shared_ptr theLine2, + boost::shared_ptr thePlane); + + /** \brief Assigns the color for the shape + * \param[in] theColor index of the color + */ + void setColor(const int& theColor); + + /// \brief Assigns the width of the lines of shape + void setWidth(const double& theWidth); + + /// \brief Checks if the object is empty + bool empty() const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Circ.cpp b/src/GeomAPI/GeomAPI_Circ.cpp index 811ef698b..31dbfab6c 100644 --- a/src/GeomAPI/GeomAPI_Circ.cpp +++ b/src/GeomAPI/GeomAPI_Circ.cpp @@ -61,3 +61,13 @@ const boost::shared_ptr GeomAPI_Circ::project(const boost::shared_p return aResult; } +const boost::shared_ptr GeomAPI_Circ::center() const +{ + const gp_Pnt& aCenter = MY_CIRC->Location(); + return boost::shared_ptr(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z())); +} + +double GeomAPI_Circ::radius() const +{ + return MY_CIRC->Radius(); +} diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h index c1a23bbf6..dda6923c6 100644 --- a/src/GeomAPI/GeomAPI_Circ.h +++ b/src/GeomAPI/GeomAPI_Circ.h @@ -24,6 +24,12 @@ public: const boost::shared_ptr& theDir, double theRadius); + /// Return center of the circle + const boost::shared_ptr center() const; + + /// Return radius of the circle + double radius() const; + /// Project point on circle const boost::shared_ptr project(const boost::shared_ptr& thePoint) const; }; diff --git a/src/GeomAPI/GeomAPI_Circ2d.cpp b/src/GeomAPI/GeomAPI_Circ2d.cpp index 27854d2a9..78c26d69f 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.cpp +++ b/src/GeomAPI/GeomAPI_Circ2d.cpp @@ -85,3 +85,14 @@ const boost::shared_ptr GeomAPI_Circ2d::project(const boost::shar return aResult; } +const boost::shared_ptr GeomAPI_Circ2d::center() const +{ + const gp_Pnt2d& aCenter = MY_CIRC2D->Location(); + return boost::shared_ptr(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y())); +} + +double GeomAPI_Circ2d::radius() const +{ + return MY_CIRC2D->Radius(); +} + diff --git a/src/GeomAPI/GeomAPI_Circ2d.h b/src/GeomAPI/GeomAPI_Circ2d.h index 11d18f6b6..e95d8643c 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.h +++ b/src/GeomAPI/GeomAPI_Circ2d.h @@ -28,6 +28,12 @@ public: const boost::shared_ptr& theDir, double theRadius); + /// Return center of the circle + const boost::shared_ptr center() const; + + /// Return radius of the circle + double radius() const; + /// Project point on line const boost::shared_ptr project(const boost::shared_ptr& thePoint) const; }; diff --git a/src/GeomAPI/GeomAPI_Interface.h b/src/GeomAPI/GeomAPI_Interface.h index bd9a77ab1..f77131de6 100644 --- a/src/GeomAPI/GeomAPI_Interface.h +++ b/src/GeomAPI/GeomAPI_Interface.h @@ -28,7 +28,7 @@ public: virtual ~GeomAPI_Interface(); /// Returns the pointer to the impl - template inline T* implPtr() {return dynamic_cast(myImpl);} + template inline T* implPtr() {return static_cast(myImpl);} /// Returns the reference object of the impl template inline const T& impl() {return *(static_cast(myImpl));} /// Updates the impl (deletes the old one) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp index 5941efbec..c5c8588d4 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp @@ -128,6 +128,8 @@ void GeomAlgoAPI_SketchBuilder::createFaces( BOPCol_IndexedDataMapOfShapeListOfShape aMapVE; // map between vertexes and edges BOPTools::MapShapesAndAncestors(aFeaturesCompound, TopAbs_VERTEX, TopAbs_EDGE, aMapVE); + if (aMapVE.IsEmpty()) // in case of not-initialized circle + return; gp_Dir aDirX = theDirX->impl(); gp_Dir aDirY = theDirY->impl(); @@ -250,10 +252,16 @@ void GeomAlgoAPI_SketchBuilder::createFaces( { std::list::reverse_iterator aVRIter = aProcVertexes.rbegin(); std::list::reverse_iterator aERIter = aProcEdges.rbegin(); - for (++aERIter, ++aVRIter; aERIter != aProcEdges.rend(); aERIter++, aVRIter++) + if (aVRIter != aProcVertexes.rend()) + aVRIter++; + if (aERIter != aProcEdges.rend()) + aERIter++; + + for ( ; aERIter != aProcEdges.rend(); aERIter++, aVRIter++) if (aMapVE.FindFromKey(*aVRIter).Size() > 2) break; - if (aERIter != aProcEdges.rend() || aMapVE.FindFromKey(*aVRIter).Size() == 1) + if (aERIter != aProcEdges.rend() || + (aVRIter != aProcVertexes.rend() && aMapVE.FindFromKey(*aVRIter).Size() == 1)) { // the branching vertex was found or current list of edges is a wire without branches std::list::iterator aEIter; TopoDS_Shape aCurEdge; @@ -295,7 +303,8 @@ void GeomAlgoAPI_SketchBuilder::createFaces( aProcVertexes.reverse(); aProcEdges.reverse(); aNextVertex = aProcVertexes.back(); - aNextDir = getOuterEdgeDirection(aProcEdges.back(), aNextVertex); + aNextDir = aProcEdges.empty() ? aDirY : + getOuterEdgeDirection(aProcEdges.back(), aNextVertex); } } @@ -497,7 +506,8 @@ void createFace(const TopoDS_Shape& theStartVertex, for ( ; anEdgeIter != theEndOfEdges; anEdgeIter++) { TopoDS_Edge anEdge = *((TopoDS_Edge*)(&(*anEdgeIter))); - addEdgeToWire(anEdge, aBuilder, aCurVertex, aResWire); + if (!anEdge.IsNull()) + addEdgeToWire(anEdge, aBuilder, aCurVertex, aResWire); } BRepBuilderAPI_MakeFace aFaceBuilder(thePlane, aResWire); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 206bbaa5b..1cef3112f 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -40,9 +40,7 @@ #include #include - -#include -//#include +#include #include #include @@ -439,7 +437,8 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, boost::dynamic_pointer_cast(theFeature); if (aSPFeature) { - Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(aDisplayer->getAISObject(theFeature)); + boost::shared_ptr anAIS = + aSPFeature->getAISObject(aDisplayer->getAISObject(theFeature)); aDisplayer->redisplay(theFeature, anAIS, false); } } diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index 75a16c52d..00ff7cef2 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -37,8 +37,8 @@ void PartSet_TestOCC::testSelection(XGUI_Workshop* theWorkshop) theWorkshop->viewer()->activeView()); PartSet_TestOCC::changeTestLine(theWorkshop); } - Handle(AIS_InteractiveObject) anIO = theWorkshop->displayer()->getAISObject(myTestFeature); - if (!anIO.IsNull()) { + boost::shared_ptr anIO = theWorkshop->displayer()->getAISObject(myTestFeature); + if (!anIO->empty()) { theWorkshop->viewer()->AISContext()->MoveTo(0, 0, theWorkshop->viewer()->activeView()); theWorkshop->viewer()->AISContext()->Select(0, 0, 2500, 2500, theWorkshop->viewer()->activeView()); } @@ -147,10 +147,11 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) XGUI_Displayer* aDisplayer = theWorkshop->displayer(); + boost::shared_ptr aPrevAIS; boost::shared_ptr aSPFeature = boost::dynamic_pointer_cast(aFeature); - Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(NULL); - if (!anAIS.IsNull()) + boost::shared_ptr anAIS = aSPFeature->getAISObject(aPrevAIS); + if (!anAIS->empty()) aDisplayer->redisplay(aFeature, anAIS, false); std::list aModes; @@ -202,11 +203,11 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop) PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END); boost::shared_ptr aPreview = PartSet_OperationSketchBase::preview(aFeature); - Handle(AIS_InteractiveObject) aPrevAIS; + boost::shared_ptr aPrevAIS; boost::shared_ptr aSPFeature = boost::dynamic_pointer_cast(aFeature); - Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(aPrevAIS); - if (!anAIS.IsNull()) + boost::shared_ptr anAIS = aSPFeature->getAISObject(aPrevAIS); + if (!anAIS->empty()) theWorkshop->displayer()->redisplay(aFeature, anAIS, true); //std::list aModes; //aModes.clear(); diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 1533afdda..2bbac462f 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -39,15 +39,13 @@ SET(PROJECT_LIBRARIES GeomAPI GeomAlgoAPI ModelAPI - ${CAS_KERNEL} - ${CAS_VIEWER} ) SET(XML_RESOURCES plugin-Sketch.xml ) -ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS} ${CAS_DEFINITIONS}) +ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES}) TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES}) @@ -56,7 +54,6 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../GeomDataAPI - ${CAS_INCLUDE_DIRS} ) INSTALL(TARGETS SketchPlugin DESTINATION plugins) diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index c0891d80d..e166608d1 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -16,7 +16,7 @@ #include #include -#include +const double tolerance = 1e-7; SketchPlugin_Arc::SketchPlugin_Arc() : SketchPlugin_Feature() @@ -68,7 +68,7 @@ const boost::shared_ptr& SketchPlugin_Arc::preview() boost::shared_ptr aCircleForArc( new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt())); boost::shared_ptr aProjection = aCircleForArc->project(anEndAttr->pnt()); - if (aProjection && anEndAttr->pnt()->distance(aProjection) > Precision::Confusion()) + if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance) anEndAttr->setValue(aProjection); } boost::shared_ptr aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); @@ -85,6 +85,12 @@ const boost::shared_ptr& SketchPlugin_Arc::preview() return getPreview(); } +boost::shared_ptr SketchPlugin_Arc::getAISObject( + boost::shared_ptr thePrevious) +{ + return prepareAISShape(thePrevious); +} + void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) { boost::shared_ptr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index b40024b8b..946607795 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -43,6 +43,10 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub( diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index cca6599bb..9d2cda07b 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -69,6 +69,12 @@ const boost::shared_ptr& SketchPlugin_Circle::preview() return getPreview(); } +boost::shared_ptr SketchPlugin_Circle::getAISObject( + boost::shared_ptr thePrevious) +{ + return prepareAISShape(thePrevious); +} + void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY) { boost::shared_ptr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index e81107b30..bb47c214d 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -41,6 +41,10 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub( diff --git a/src/SketchPlugin/SketchPlugin_Constraint.cpp b/src/SketchPlugin/SketchPlugin_Constraint.cpp index 70a980aec..5e8727687 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.cpp +++ b/src/SketchPlugin/SketchPlugin_Constraint.cpp @@ -4,9 +4,8 @@ #include "SketchPlugin_Constraint.h" -#include - -Handle_AIS_InteractiveObject SketchPlugin_Constraint::getAISShape(Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_Constraint::getAISObject( + boost::shared_ptr thePrevious) { return thePrevious; } diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index 632243ba6..5db923562 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -12,9 +12,6 @@ #include #include -const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint -const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance - /* Description: * Each constraint uses a set of parameters. In the SolveSpace library @@ -69,7 +66,8 @@ public: SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 0e8d30b6a..faa2d7b62 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -12,10 +12,6 @@ #include #include -#include -#include -#include - /// Obtain the point object from specified constraint parameter static boost::shared_ptr getFeaturePoint( DataPtr theData, @@ -50,8 +46,8 @@ void SketchPlugin_ConstraintDistance::execute() } } -Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape( - Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_ConstraintDistance::getAISObject( + boost::shared_ptr thePrevious) { if (!sketch()) return thePrevious; @@ -64,62 +60,24 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape( if (!aPoint_A || !aPoint_B) return thePrevious; - // fly out calculation boost::shared_ptr aFlyOutAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - double aFlyout = 0; - if (aFlyOutAttr->isInitialized()) { - boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); - - boost::shared_ptr aFeatureLin = - boost::shared_ptr(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), - aPoint_B->x(), aPoint_B->y())); - boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); - double aDistance = aFlyOutPnt->distance(aProjectedPoint); - if (!aFeatureLin->isRight(aFlyOutPnt)) - aDistance = -aDistance; - aFlyout = aDistance; - } - //Build dimension here boost::shared_ptr aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y()); boost::shared_ptr aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y()); + boost::shared_ptr aFlyoutPnt = aFlyOutAttr->isInitialized() ? + sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()) : + boost::shared_ptr(); // value calculation boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); double aValue = aValueAttr->value(); - Handle(AIS_InteractiveObject) anAIS = thePrevious; - if (anAIS.IsNull()) - { - Handle(AIS_LengthDimension) aDimAIS = - new AIS_LengthDimension(aPoint1->impl(), aPoint2->impl(), aPlane->impl()); - aDimAIS->SetCustomValue(aValue); - - Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d (Standard_False); - anAspect->MakeText3d(false); - anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); - anAspect->MakeTextShaded(false); - aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); - aDimAIS->SetDimensionAspect (anAspect); - aDimAIS->SetFlyout(aFlyout); - aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); - - anAIS = aDimAIS; - } - else { - // update presentation - Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); - if (!aDimAIS.IsNull()) { - aDimAIS->SetMeasuredGeometry(aPoint1->impl(), aPoint2->impl(), aPlane->impl()); - aDimAIS->SetCustomValue(aValue); - aDimAIS->SetFlyout(aFlyout); - - aDimAIS->Redisplay(Standard_True); - } - } + boost::shared_ptr anAIS = thePrevious; + if (!anAIS) + anAIS = boost::shared_ptr(new GeomAPI_AISObject); + anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 4ffbaf9c7..4350e3cb4 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -39,7 +39,8 @@ public: SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index dac5f926b..71a35c4f1 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -15,10 +15,6 @@ #include #include -#include -#include -#include - SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength() { } @@ -54,8 +50,8 @@ void SketchPlugin_ConstraintLength::execute() } } -Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape( - Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_ConstraintLength::getAISObject( + boost::shared_ptr thePrevious) { if (!sketch()) return thePrevious; @@ -70,81 +66,30 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape( if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) return thePrevious; - // fly out calculation boost::shared_ptr aFlyOutAttr = boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - double aFlyout = 0; - if (aFlyOutAttr->isInitialized()) { - boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); - - boost::shared_ptr aStartPoint = - boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_START)); - boost::shared_ptr anEndPoint = - boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_END)); - - boost::shared_ptr aFeatureLin = boost::shared_ptr - (new GeomAPI_Lin2d(aStartPoint->x(), aStartPoint->y(), - anEndPoint->x(), anEndPoint->y())); - boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); - double aDistance = aFlyOutPnt->distance(aProjectedPoint); - if (!aFeatureLin->isRight(aFlyOutPnt)) - aDistance = -aDistance; - aFlyout = aDistance; - } - // value + + DataPtr aData = aFeature->data(); + boost::shared_ptr aStartPoint = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr anEndPoint = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + boost::shared_ptr aPoint1 = sketch()->to3D(aStartPoint->x(), aStartPoint->y()); + boost::shared_ptr aPoint2 = sketch()->to3D(anEndPoint->x(), anEndPoint->y()); + boost::shared_ptr aFlyoutPnt = aFlyOutAttr->isInitialized() ? + sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()) : + boost::shared_ptr(); + + // value calculation boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); double aValue = aValueAttr->value(); - boost::shared_ptr aData = aFeature->data(); - if (!aData->isValid()) - return thePrevious; - - boost::shared_ptr aPointStart = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPointEnd = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - - //Build dimension here - boost::shared_ptr aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y()); - boost::shared_ptr aPoint2 = sketch()->to3D(aPointEnd->x(), aPointEnd->y()); - - Handle(AIS_InteractiveObject) anAIS = thePrevious; - if (anAIS.IsNull()) - { - Handle(AIS_LengthDimension) aDimAIS = - new AIS_LengthDimension(aPoint1->impl(), aPoint2->impl(), aPlane->impl()); - aDimAIS->SetCustomValue(aValue); - - Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d (Standard_False); - anAspect->MakeText3d(false/*is text 3d*/); - anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); - anAspect->MakeTextShaded(false/*is test shaded*/); - aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/); - /*if (isUnitsDisplayed) - { - aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ()); - }*/ - aDimAIS->SetDimensionAspect (anAspect); - aDimAIS->SetFlyout(aFlyout); - aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); - - anAIS = aDimAIS; - } - else - { - // update presentation - Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); - if (!aDimAIS.IsNull()) - { - aDimAIS->SetMeasuredGeometry(aPoint1->impl(), aPoint2->impl(), aPlane->impl()); - aDimAIS->SetCustomValue(aValue); - aDimAIS->SetFlyout(aFlyout); - - aDimAIS->Redisplay(Standard_True); - } - } + boost::shared_ptr anAIS = thePrevious; + if (!anAIS) + anAIS = boost::shared_ptr(new GeomAPI_AISObject); + anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 85675da3b..3d07ce186 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -39,7 +39,8 @@ public: SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index f77c95d27..e45980582 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -10,10 +10,6 @@ #include #include -#include -#include -#include - #include #include #include @@ -40,11 +36,11 @@ const boost::shared_ptr& SketchPlugin_ConstraintParallel::previe } -Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_ConstraintParallel::getAISObject( + boost::shared_ptr thePrevious) { - Handle(AIS_InteractiveObject) anAIS = thePrevious; if (!sketch()) - return anAIS; + return thePrevious; boost::shared_ptr aData = data(); boost::shared_ptr anAttr1 = @@ -53,42 +49,26 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); if (!anAttr1 || !anAttr1->isFeature() || !anAttr2 || !anAttr2->isFeature()) - return anAIS; + return thePrevious; boost::shared_ptr aLine1Feature = boost::dynamic_pointer_cast(anAttr1->feature()); boost::shared_ptr aLine2Feature = boost::dynamic_pointer_cast(anAttr2->feature()); if (!aLine1Feature || !aLine2Feature) - return anAIS; + return thePrevious; + boost::shared_ptr aPlane = sketch()->plane(); boost::shared_ptr aLine1 = aLine1Feature->preview(); boost::shared_ptr aLine2 = aLine2Feature->preview(); - Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); boost::shared_ptr aFlyoutAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - boost::shared_ptr aFOPnt2d = aFlyoutAttr->pnt(); - boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y()); - - if (anAIS.IsNull()) - { - Handle(AIS_ParallelRelation) aParallel = - new AIS_ParallelRelation(aLine1->impl(), aLine2->impl(), aPlane); - aParallel->SetPosition(aFlyoutPnt->impl()); - anAIS = aParallel; - } - else - { - Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS); - if (!aParallel.IsNull()) - { - aParallel->SetFirstShape(aLine1->impl()); - aParallel->SetSecondShape(aLine2->impl()); - aParallel->SetPlane(aPlane); - aParallel->SetPosition(aFlyoutPnt->impl()); - aParallel->Redisplay(Standard_True); - } - } + boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + + boost::shared_ptr anAIS = thePrevious; + if (!anAIS) + anAIS = boost::shared_ptr(new GeomAPI_AISObject); + anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index 9496f0722..7f92e2e56 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -40,7 +40,8 @@ public: SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index 1b6cc4d09..d4d73b003 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -10,10 +10,6 @@ #include #include -#include -#include -#include - #include #include #include @@ -39,11 +35,11 @@ const boost::shared_ptr& SketchPlugin_ConstraintPerpendicular::p return getPreview(); } -Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_ConstraintPerpendicular::getAISObject( + boost::shared_ptr thePrevious) { - Handle(AIS_InteractiveObject) anAIS = thePrevious; if (!sketch()) - return anAIS; + return thePrevious; boost::shared_ptr aData = data(); boost::shared_ptr anAttr1 = @@ -52,42 +48,22 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(H boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); if (!anAttr1 || !anAttr1->isFeature() || !anAttr2 || !anAttr2->isFeature()) - return anAIS; + return thePrevious; boost::shared_ptr aLine1Feature = boost::dynamic_pointer_cast(anAttr1->feature()); boost::shared_ptr aLine2Feature = boost::dynamic_pointer_cast(anAttr2->feature()); if (!aLine1Feature || !aLine2Feature) - return anAIS; + return thePrevious; + boost::shared_ptr aPlane = sketch()->plane(); boost::shared_ptr aLine1 = aLine1Feature->preview(); boost::shared_ptr aLine2 = aLine2Feature->preview(); - Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); - - boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - boost::shared_ptr aFOPnt2d = aFlyoutAttr->pnt(); - boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y()); - if (anAIS.IsNull()) - { - Handle(AIS_PerpendicularRelation) aPerpendicular = - new AIS_PerpendicularRelation(aLine1->impl(), aLine2->impl(), aPlane); - aPerpendicular->SetPosition(aFlyoutPnt->impl()); - anAIS = aPerpendicular; - } - else - { - Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS); - if (!aPerpendicular.IsNull()) - { - aPerpendicular->SetFirstShape(aLine1->impl()); - aPerpendicular->SetSecondShape(aLine2->impl()); - aPerpendicular->SetPlane(aPlane); - aPerpendicular->SetPosition(aFlyoutPnt->impl()); - aPerpendicular->Redisplay(Standard_True); - } - } + boost::shared_ptr anAIS = thePrevious; + if (!anAIS) + anAIS = boost::shared_ptr(new GeomAPI_AISObject); + anAIS->createPerpendicular(aLine1, aLine2, aPlane); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index c960f50e8..2bb4a7b63 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -40,7 +40,8 @@ public: SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 391dbd451..65ab125b5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -19,9 +19,6 @@ #include #include -#include -#include - SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius() { } @@ -65,35 +62,30 @@ void SketchPlugin_ConstraintRadius::execute() } } -Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( - Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_ConstraintRadius::getAISObject( + boost::shared_ptr thePrevious) { - Handle(AIS_InteractiveObject) anAIS = thePrevious; if (!sketch()) - return anAIS; + return thePrevious; boost::shared_ptr aData = data(); boost::shared_ptr anAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); if (!anAttr) - return anAIS; + return thePrevious; FeaturePtr aFeature = anAttr->feature(); std::string aKind = aFeature ? aFeature->getKind() : ""; if (aKind != SKETCH_CIRCLE_KIND && aKind != SKETCH_ARC_KIND) - return anAIS; - - boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); - double aValue = aValueAttr->value(); + return thePrevious; - // an anchor point - boost::shared_ptr aAnchorAttr = + // Flyout point + boost::shared_ptr aFlyoutAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - if (!aAnchorAttr->isInitialized()) - return anAIS; - boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); - boost::shared_ptr anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y()); + if (!aFlyoutAttr->isInitialized()) + return thePrevious; + boost::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); + // Prepare a circle aData = aFeature->data(); boost::shared_ptr aCenterAttr; double aRadius; @@ -110,58 +102,23 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); } - // a circle boost::shared_ptr aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y()); - boost::shared_ptr aNDir = boost::dynamic_pointer_cast(sketch()->data()->attribute(SKETCH_ATTR_NORM)); boost::shared_ptr aNormal = aNDir->dir(); - boost::shared_ptr aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius)); - anAnchor = aCircle->project(anAnchor); - // TODO: a bug in AIS_RadiusDimension: - // The anchor point can't be myCirc.Location() - an exception is raised. - // But we need exactly this case... - // 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 anAnchorXYZ = anAnchor->xyz(); - anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz()); - boost::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()); - - if (anAIS.IsNull()) - { - Handle(AIS_RadiusDimension) aDimAIS = - new AIS_RadiusDimension(aCircle->impl(), anAnchor->impl()); - aDimAIS->SetCustomValue(aValue); - - Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d (Standard_False); - anAspect->MakeText3d(false); - anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); - anAspect->MakeTextShaded(false); - aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false); - aDimAIS->SetDimensionAspect (anAspect); - aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); - - anAIS = aDimAIS; - } - else - { - // update presentation - Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS); - if (!aDimAIS.IsNull()) - { - aDimAIS->SetMeasuredGeometry(aCircle->impl(), anAnchor->impl()); - aDimAIS->SetCustomValue(aValue); - aDimAIS->Redisplay(Standard_True); - } - } + // Value + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aValue = aRadius; + if (aValueAttr && aValueAttr->isInitialized()) + aValue = aValueAttr->value(); + + boost::shared_ptr anAIS = thePrevious; + if (!anAIS) + anAIS = boost::shared_ptr(new GeomAPI_AISObject); + anAIS->createRadius(aCircle, aFlyoutPnt, aValue); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index a8ef9bb6b..a2e9abad8 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -38,7 +38,8 @@ public: SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 6a7e12f5d..4404ea1b8 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -5,10 +5,6 @@ #include #include -#include -#include -#include - SketchPlugin_Feature::SketchPlugin_Feature() { mySketch = 0; @@ -48,29 +44,13 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch() return mySketch; } -Handle(AIS_InteractiveObject) SketchPlugin_Feature::getAISShape(Handle(AIS_InteractiveObject) thePrevious) +boost::shared_ptr SketchPlugin_Feature::prepareAISShape( + boost::shared_ptr thePrevious) { boost::shared_ptr aPreview = preview(); - - Handle(AIS_InteractiveObject) anAIS = thePrevious; - const TopoDS_Shape& aShape = aPreview ? aPreview->impl() : TopoDS_Shape(); - if (!anAIS.IsNull()) - { - Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); - if (!aShapeAIS.IsNull()) { - // 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 - // after. Another workaround to thrown down the selection and reselecting the AIS. - // If there was a problem here, try the first solution with close/open local context. - - aShapeAIS->Set(aShape); - aShapeAIS->Redisplay(Standard_True); - } - } - else - { - anAIS = new AIS_Shape(aShape); - } - return anAIS; + boost::shared_ptr aResult = thePrevious; + if (!aResult) + aResult = boost::shared_ptr(new GeomAPI_AISObject()); + aResult->createShape(aPreview); + return aResult; } diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 084763958..1cddba03f 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -8,6 +8,7 @@ #include "SketchPlugin.h" #include #include +#include class SketchPlugin_Sketch; class GeomAPI_Pnt2d; @@ -27,7 +28,8 @@ public: SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview() = 0; /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious) = 0; /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature @@ -53,6 +55,9 @@ protected: /// Return the shape from the internal preview field /// \return theShape a preview shape const boost::shared_ptr& getPreview() const; + /// Common method for other features to produce AIS shape + boost::shared_ptr prepareAISShape( + boost::shared_ptr thePrevious); /// Sets the higher-level feature for the sub-feature (sketch for line) void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;} /// Returns the sketch of this feature diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 8f8df8304..3175ac13f 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -13,8 +13,6 @@ #include #include -#include - using namespace std; // face of the square-face displayed for selection of general plane @@ -56,6 +54,13 @@ const boost::shared_ptr& SketchPlugin_Line::preview() return getPreview(); } +boost::shared_ptr SketchPlugin_Line::getAISObject( + boost::shared_ptr thePrevious) +{ + return prepareAISShape(thePrevious); +} + + void SketchPlugin_Line::move(double theDeltaX, double theDeltaY) { boost::shared_ptr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index c6d23b2ef..f440bac1d 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -42,6 +42,10 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub( diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 74860bb62..984d98919 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -42,6 +42,12 @@ const boost::shared_ptr& SketchPlugin_Point::preview() return getPreview(); } +boost::shared_ptr SketchPlugin_Point::getAISObject( + boost::shared_ptr thePrevious) +{ + return prepareAISShape(thePrevious); +} + void SketchPlugin_Point::move(double theDeltaX, double theDeltaY) { boost::shared_ptr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index be36d016f..31fad0ea4 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -40,6 +40,10 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub( diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 81ead9d7d..50506850e 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -5,6 +5,7 @@ #include "SketchPlugin_Sketch.h" #include #include +#include #include #include #include @@ -12,13 +13,9 @@ #include #include -#include -#include -#include - -const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color -const int SKETCH_WIDTH = 4; /// the plane edge width +const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color +const double SKETCH_WIDTH = 4.0; /// the plane edge width using namespace std; @@ -80,13 +77,13 @@ void SketchPlugin_Sketch::execute() data()->store(aCompound); } -Handle(AIS_InteractiveObject) SketchPlugin_Sketch::getAISShape(Handle(AIS_InteractiveObject) thePrevious) +boost::shared_ptr SketchPlugin_Sketch::getAISObject( + boost::shared_ptr thePrevious) { - Handle(AIS_InteractiveObject) anAIS = SketchPlugin_Feature::getAISShape(thePrevious); - Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); - aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR)); - aShapeAIS->SetWidth(SKETCH_WIDTH); - aShapeAIS->Redisplay(); + boost::shared_ptr anAIS = prepareAISShape(thePrevious); + anAIS->setColor(SKETCH_PLANE_COLOR); + anAIS->setWidth(SKETCH_WIDTH); + //anAIS->Redisplay(); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 1f16d72ca..d88267bed 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -49,8 +49,9 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); - /// Returns the sketch preview - SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious); + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3da77af53..f93b9502d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -47,20 +47,22 @@ void XGUI_Displayer::display(FeaturePtr theFeature, bool isUpdateViewer) boost::shared_ptr aShapePtr = aFeature->data()->shape(); if (aShapePtr) { - TopoDS_Shape aShape = aShapePtr->impl(); - display(aFeature, aShape, isUpdateViewer); + boost::shared_ptr anAIS(new GeomAPI_AISObject()); + anAIS->createShape(aShapePtr); + display(aFeature, anAIS, isUpdateViewer); } } void XGUI_Displayer::display(FeaturePtr theFeature, - const TopoDS_Shape& theShape, bool isUpdateViewer) + boost::shared_ptr theAIS, bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); - Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); - myFeature2AISObjectMap[theFeature] = anAIS; + myFeature2AISObjectMap[theFeature] = theAIS; - aContext->Display(anAIS, isUpdateViewer); + Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); + if (!anAISIO.IsNull()) + aContext->Display(anAISIO, isUpdateViewer); } @@ -133,20 +135,24 @@ void XGUI_Displayer::erase(FeaturePtr theFeature, return; Handle(AIS_InteractiveContext) aContext = AISContext(); - Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aFeature]; - if (!anAIS.IsNull()) + boost::shared_ptr anObject = myFeature2AISObjectMap[aFeature]; + if (anObject) { - aContext->Erase(anAIS, isUpdateViewer); + Handle(AIS_InteractiveObject) anAIS = anObject->impl(); + if (!anAIS.IsNull()) + aContext->Erase(anAIS, isUpdateViewer); } myFeature2AISObjectMap.erase(aFeature); } bool XGUI_Displayer::redisplay(FeaturePtr theFeature, - Handle(AIS_InteractiveObject) theAIS, + boost::shared_ptr theAIS, const bool isUpdateViewer) { bool isCreated = false; + Handle(AIS_InteractiveObject) anAIS = + theAIS ? theAIS->impl() : Handle(AIS_InteractiveObject)(); Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one if (!aContext->HasOpenedContext()) { @@ -157,12 +163,13 @@ bool XGUI_Displayer::redisplay(FeaturePtr theFeature, //aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL); } // display or redisplay presentation - if (isVisible(theFeature) && !myFeature2AISObjectMap[theFeature].IsNull()) { - aContext->RecomputeSelectionOnly(theAIS); + boost::shared_ptr anObj = myFeature2AISObjectMap[theFeature]; + if (isVisible(theFeature) && anObj && !anObj->empty()) { + aContext->RecomputeSelectionOnly(anAIS); } else { myFeature2AISObjectMap[theFeature] = theAIS; - aContext->Display(theAIS, false); + aContext->Display(anAIS, false); isCreated = true; } if (isUpdateViewer) @@ -179,10 +186,12 @@ void XGUI_Displayer::redisplay(FeaturePtr theFeature, bool isUpdateViewer) boost::shared_ptr aShapePtr = aFeature->data()->shape(); if (aShapePtr) { - Handle(AIS_InteractiveObject) aAISObj = getAISObject(aFeature); - Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj); - aAISShape->Set(aShapePtr->impl()); + boost::shared_ptr aAISObj = getAISObject(aFeature); + Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj->impl()); + if (!aAISShape.IsNull()) + return; + aAISShape->Set(aShapePtr->impl()); AISContext()->Redisplay(aAISShape); } } @@ -199,18 +208,22 @@ void XGUI_Displayer::activateInLocalContext(FeaturePtr theFeature, // display or redisplay presentation Handle(AIS_InteractiveObject) anAIS; if (isVisible(theFeature)) - anAIS = Handle(AIS_InteractiveObject)::DownCast(myFeature2AISObjectMap[theFeature]); + { + boost::shared_ptr anObj = myFeature2AISObjectMap[theFeature]; + if (anObj) + anAIS = anObj->impl(); + } // Activate selection of objects from prs if (!anAIS.IsNull()) { - aContext->Load(anAIS, -1, true/*allow decomposition*/); + aContext->Load(anAIS, -1, true/*allow decomposition*/); aContext->Deactivate(anAIS); std::list::const_iterator anIt = theModes.begin(), aLast = theModes.end(); for (; anIt != aLast; anIt++) { aContext->Activate(anAIS, (*anIt)); - } + } } if (isUpdateViewer) @@ -228,7 +241,7 @@ void XGUI_Displayer::stopSelection(const QFeatureList& theFeatures, const bool i for (; anIt != aLast; anIt++) { aFeature = *anIt; if (isVisible(aFeature)) - anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]); + anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]->impl()); if (anAIS.IsNull()) continue; @@ -262,9 +275,13 @@ void XGUI_Displayer::setSelected(const QFeatureList& theFeatures, const bool isU if (myFeature2AISObjectMap.find(aRFeature) == myFeature2AISObjectMap.end()) return; - Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aRFeature]; - if (!anAIS.IsNull()) - aContext->AddOrRemoveSelected(anAIS, false); + boost::shared_ptr anObj = myFeature2AISObjectMap[aRFeature]; + if (anObj) + { + Handle(AIS_InteractiveObject) anAIS = anObj->impl(); + if (!anAIS.IsNull()) + aContext->AddOrRemoveSelected(anAIS, false); + } } if (isUpdateViewer) updateViewer(); @@ -302,7 +319,9 @@ void XGUI_Displayer::eraseDeletedFeatures(const bool isUpdateViewer) { FeaturePtr aFeature = (*aFIt).first; if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) { - Handle(AIS_InteractiveObject) anAIS = (*aFIt).second; + boost::shared_ptr anObj = (*aFIt).second; + if (!anObj) continue; + Handle(AIS_InteractiveObject) anAIS = anObj->impl(); if (!anAIS.IsNull()) { aContext->Erase(anAIS, false); aRemoved.push_back(aFeature); @@ -324,10 +343,10 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) closeAllContexts(true); } -Handle(AIS_InteractiveObject) XGUI_Displayer::getAISObject( +boost::shared_ptr XGUI_Displayer::getAISObject( FeaturePtr theFeature) const { - Handle(AIS_InteractiveObject) anIO; + boost::shared_ptr anIO; if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) anIO = (myFeature2AISObjectMap.find(theFeature))->second; return anIO; @@ -339,7 +358,9 @@ FeaturePtr XGUI_Displayer::getFeature(Handle(AIS_InteractiveObject) theIO) const FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(), aFLast = myFeature2AISObjectMap.end(); for (; aFIt != aFLast && !aFeature; aFIt++) { - Handle(AIS_InteractiveObject) anAIS = (*aFIt).second; + boost::shared_ptr anObj = (*aFIt).second; + if (!anObj) continue; + Handle(AIS_InteractiveObject) anAIS = anObj->impl(); if (anAIS != theIO) continue; aFeature = (*aFIt).first; diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index f5402c351..7652165fa 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -11,6 +11,8 @@ #include #include +#include + #include #include #include @@ -56,9 +58,9 @@ public: /// Display the feature and a shape. This shape would be associated to the given feature /// \param theFeature a feature instance - /// \param theShape a shape + /// \param theAIS AIS presentation /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void display(FeaturePtr theFeature, const TopoDS_Shape& theShape, bool isUpdateViewer = true); + void display(FeaturePtr theFeature, boost::shared_ptr theAIS, bool isUpdateViewer = true); /// Returns a list of viewer selected presentations /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build @@ -81,7 +83,8 @@ public: /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly /// \returns true if the presentation is created bool redisplay(FeaturePtr theFeature, - Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true); + boost::shared_ptr theAIS, + const bool isUpdateViewer = true); /** Redisplay the shape if it was displayed * \param theFeature a feature instance @@ -139,7 +142,7 @@ public: /// Searches the interactive object by feature /// \param theFeature the feature or NULL if it not visualized /// \return theIO an interactive object - Handle(AIS_InteractiveObject) getAISObject(FeaturePtr theFeature) const; + boost::shared_ptr getAISObject(FeaturePtr theFeature) const; protected: /// Searches the feature by interactive object @@ -156,7 +159,7 @@ protected: protected: XGUI_Workshop* myWorkshop; - typedef std::map FeatureToAISMap; + typedef std::map > FeatureToAISMap; FeatureToAISMap myFeature2AISObjectMap; }; -- 2.39.2