From 2136782ef0f410c48485d75704779ceedf7a29c1 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 22 Jun 2015 14:03:45 +0300 Subject: [PATCH] Issue #555 - Make a number of shifted/rotated copies - selected object does not appear in List of objects It provides an infinite state for plane/axis shapes. --- .../ConstructionPlugin_Axis.cpp | 4 +-- src/GeomAPI/GeomAPI_AISObject.cpp | 15 ---------- src/GeomAPI/GeomAPI_AISObject.h | 7 ----- src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp | 7 ++++- src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h | 10 +++++-- src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 8 +++-- src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h | 3 +- src/PartSet/PartSet_FilterInfinite.cpp | 29 +++++++++++++++++-- src/PartSet/PartSet_Module.cpp | 6 ++++ src/PartSet/PartSet_Module.h | 2 ++ src/PartSet/PartSet_SketcherMgr.cpp | 9 ------ src/PartSet/PartSet_SketcherMgr.h | 3 -- 12 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 8741df7dc..60b9833c3 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -53,7 +53,7 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aShape2); if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) { - std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd, true); ResultConstructionPtr aConstr = document()->createConstruction(data()); aConstr->setShape(anEdge); @@ -96,7 +96,5 @@ bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObje isCustomized = thePrs->setLineStyle(3) || isCustomized; isCustomized = thePrs->setWidth(2) || isCustomized; - thePrs->setInfiniteState(true); - return isCustomized; } diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 8c98c449c..681926a68 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -392,21 +392,6 @@ bool GeomAPI_AISObject::setLineStyle(int theStyle) return isChanged; } -bool GeomAPI_AISObject::setInfiniteState(const bool theState) -{ - bool isChanged = false; - Handle(AIS_InteractiveObject) anAIS = impl(); - if (!anAIS.IsNull() && anAIS->IsInfinite() != theState) { - anAIS->SetInfiniteState(theState); - isChanged = true; - - bool isInfinite = anAIS->IsInfinite(); - int aValue = 9; - } - return isChanged; -} - - bool GeomAPI_AISObject::setTransparensy(double theVal) { bool isChanged = false; diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index 6652a4279..06bc2e905 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -119,13 +119,6 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface /// \returns true if the object value differs from the current bool setLineStyle(int theStyle); - //! Sets the infinite state flag aFlage. - //! considered as infinite, i.e. its graphic presentations - //! are not taken in account for View FitAll... - //! \param theState a state - /// \returns true if the object value differs from the current - bool setInfiniteState(const bool theState); - /// Set transparency of the presentation (theVal = 0 ... 1) /// \returns true if the object value differs from the current bool setTransparensy(double theVal); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index 0de55a60f..fcf8dbb2b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -18,7 +18,8 @@ #include std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( - std::shared_ptr theStart, std::shared_ptr theEnd) + std::shared_ptr theStart, std::shared_ptr theEnd, + const bool theInfinite) { const gp_Pnt& aStart = theStart->impl(); const gp_Pnt& anEnd = theEnd->impl(); @@ -30,6 +31,8 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); std::shared_ptr aRes(new GeomAPI_Edge); TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + if (theInfinite) + anEdge.Infinite(Standard_True); aRes->setImpl(new TopoDS_Shape(anEdge)); return aRes; } @@ -60,6 +63,8 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::cylinderAxis( BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); std::shared_ptr aRes(new GeomAPI_Edge); TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + // an axis is an infinite object + anEdge.Infinite(Standard_True); aRes->setImpl(new TopoDS_Shape(anEdge)); return aRes; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index 0bd67621b..1de252482 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -21,10 +21,14 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder { public: - /// Creates linear edge by two points + /// Creates linear edge by two points. + /// \param theStart a first point of an edge + /// \param theEnd an end point of an edge + /// \param theInfinite if true, the shape of the edge is infinite. It is used for axis edge. static std::shared_ptr line(std::shared_ptr theStart, - std::shared_ptr theEnd); - /// Creates edge - axis of the given cylindrical face + std::shared_ptr theEnd, + const bool theInfinite = false); + /// Creates edge - axis of the given cylindrical face. The result axis edge is infinite static std::shared_ptr cylinderAxis( std::shared_ptr theCylindricalFace); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index c19787308..9e687d6d2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -31,14 +31,18 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::square( std::shared_ptr GeomAlgoAPI_FaceBuilder::square( std::shared_ptr thePlane, - const double theSize) + const double theSize, + const bool theInfinite) { // half of the size in each direction from the center BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl(), -theSize / 2., theSize / 2., -theSize / 2., theSize / 2.); std::shared_ptr aRes(new GeomAPI_Shape); - aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); + TopoDS_Shape aFace = aFaceBuilder.Face(); + if (theInfinite) + aFace.Infinite(Standard_True); + aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/)); return aRes; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h index 49ec19c30..7b68fadcb 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -30,7 +30,8 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder /// Creates square planar face by given point of the center, /// normal to the plane and size of square static std::shared_ptr square(std::shared_ptr thePlane, - const double theSize); + const double theSize, + const bool theInfinite = false); /// Returns the plane of the planar face. If it is not planar, returns empty ptr. static std::shared_ptr plane(std::shared_ptr theFace); diff --git a/src/PartSet/PartSet_FilterInfinite.cpp b/src/PartSet/PartSet_FilterInfinite.cpp index 28f679550..015701265 100755 --- a/src/PartSet/PartSet_FilterInfinite.cpp +++ b/src/PartSet/PartSet_FilterInfinite.cpp @@ -7,16 +7,39 @@ #include "PartSet_FilterInfinite.h" #include +#include +#include +#include IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter); IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter); Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const { + Standard_Boolean aValid = Standard_True; Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); - if (!anAISObj.IsNull() && anAISObj->IsInfinite()) { - return Standard_False; + if (!anAISObj.IsNull()) { + Handle(AIS_InteractiveObject) anObj = + Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); + Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anObj); + if (!aAISShape.IsNull()) { + TopoDS_Shape anAISShape = aAISShape->Shape(); + if (!anAISShape.IsNull() && anAISShape.Infinite()) { + aValid = Standard_False; + // for infinite object, the selection is possible only for shapes of owners, which are coincide + // to the shape of corresponded AIS object. In other words, for axis, only edge can be selected + // (vertices are not selectable), for planes, only faces can be selected (not edges or vertices) + TopoDS_Shape anOwnerShape; + Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if( !aBRO.IsNull() ) { + anOwnerShape = aBRO->Shape(); + if (!anOwnerShape.IsNull()) { + aValid = anAISShape.ShapeType() == anOwnerShape.ShapeType(); + } + } + } + } } - return Standard_True; + return aValid; } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 6939718d0..c5852a61c 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -127,12 +127,18 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); + + if (myFilterInfinite.IsNull()) + myFilterInfinite = new PartSet_FilterInfinite(); + myWorkshop->viewer()->addSelectionFilter(myFilterInfinite); } PartSet_Module::~PartSet_Module() { if (!myDocumentShapeFilter.IsNull()) myDocumentShapeFilter.Nullify(); + if (!myFilterInfinite.IsNull()) + myFilterInfinite.Nullify(); } void PartSet_Module::registerValidators() diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index d711f072e..f4b2b978c 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -6,6 +6,7 @@ #include "PartSet.h" #include "PartSet_Filters.h" #include "PartSet_DocumentDataModel.h" +#include "PartSet_FilterInfinite.h" #include #include @@ -210,6 +211,7 @@ protected slots: /// A filter which provides selection within a current document or whole PartSet Handle(PartSet_GlobalFilter) myDocumentShapeFilter; + Handle(PartSet_FilterInfinite) myFilterInfinite; PartSet_SketcherMgr* mySketchMgr; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index b1d45d56f..216df94a9 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -157,9 +157,6 @@ PartSet_SketcherMgr::~PartSet_SketcherMgr() { if (!myPlaneFilter.IsNull()) myPlaneFilter.Nullify(); - if (!myFilterInfinite.IsNull()) - myFilterInfinite.Nullify(); - } void PartSet_SketcherMgr::onEnterViewPort() @@ -718,11 +715,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) if (myPlaneFilter.IsNull()) myPlaneFilter = new ModuleBase_ShapeInPlaneFilter(); - if (myFilterInfinite.IsNull()) - myFilterInfinite = new PartSet_FilterInfinite(); - myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter); - myModule->workshop()->viewer()->addSelectionFilter(myFilterInfinite); bool aHasPlane = false; if (theOperation->isEditOperation()) { @@ -755,7 +748,6 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) // The sketch was aborted myCurrentSketch = CompositeFeaturePtr(); myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter); - myModule->workshop()->viewer()->removeSelectionFilter(myFilterInfinite); // Erase all sketcher objects QStringList aSketchIds = sketchOperationIdList(); @@ -787,7 +779,6 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) myCurrentSketch = CompositeFeaturePtr(); myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter); - myModule->workshop()->viewer()->removeSelectionFilter(myFilterInfinite); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index e0a9e06f5..973924a3e 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -9,8 +9,6 @@ #include "PartSet.h" -#include "PartSet_FilterInfinite.h" - #include #include #include @@ -285,7 +283,6 @@ private: CompositeFeaturePtr myCurrentSketch; Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter; - Handle(PartSet_FilterInfinite) myFilterInfinite; FeatureToSelectionMap myCurrentSelection; bool myPreviousUpdateViewerEnabled; -- 2.39.2