Salome HOME
Issue #555: Infinite boolean state is stored in Result construction.
authornds <natalia.donis@opencascade.com>
Wed, 24 Jun 2015 12:18:44 +0000 (15:18 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 24 Jun 2015 12:18:44 +0000 (15:18 +0300)
12 files changed:
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h
src/Model/Model_ResultConstruction.cpp
src/Model/Model_ResultConstruction.h
src/ModelAPI/ModelAPI_ResultConstruction.h
src/PartSet/PartSet_FilterInfinite.cpp
src/PartSet/PartSet_FilterInfinite.h
src/PartSet/PartSet_Module.cpp

index 60b9833c35c7a9e4f45515aa940f4e41d6a05aa0..8a6c2a5d0c23fb8ea0dad5ad7b35404771e1c90c 100644 (file)
@@ -53,9 +53,10 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints()
       std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
       std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
       if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
-        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd, true);
+        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
 
         ResultConstructionPtr aConstr = document()->createConstruction(data());
+        aConstr->setInfinite(true);
         aConstr->setShape(anEdge);
         setResult(aConstr);
       }
@@ -71,6 +72,7 @@ void ConstructionPlugin_Axis::createAxisByCylindricalFace()
       std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
 
       ResultConstructionPtr aConstr = document()->createConstruction(data());
+      aConstr->setInfinite(true);
       aConstr->setShape(anEdge);
       setResult(aConstr);
     }
index 549773ab7a2902a3b041d02770e09f5fc0697bbc..adcd4c1229bdf34e622cc1adaa0a629994f60515 100644 (file)
@@ -54,6 +54,7 @@ void ConstructionPlugin_Plane::execute()
   if (!aPlaneFace.get())
     return;
   ResultConstructionPtr aConstr = document()->createConstruction(data());
+  aConstr->setInfinite(true);
   aConstr->setShape(aPlaneFace);
   setResult(aConstr);
 }
@@ -153,7 +154,7 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createPlaneByGeneralEqu
     std::string kDefaultPlaneSize = "200";
     double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
     aSize *= 4.;
-    aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize, true);
+    aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize);
   }
   return aPlaneFace;
 }
index fcf8dbb2be7716928915272dcb2fd5182c58687c..fdf2fc434a4760f5f8ff3e5d1f9c86ce692818ec 100644 (file)
@@ -18,8 +18,7 @@
 #include <gp_Circ.hxx>
 
 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
-    std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd,
-    const bool theInfinite)
+    std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd)
 {
   const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
   const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
@@ -31,8 +30,6 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
   BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
   std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
-  if (theInfinite)
-    anEdge.Infinite(Standard_True);
   aRes->setImpl(new TopoDS_Shape(anEdge));
   return aRes;
 }
index 1de252482a5414598ace8332c6646ad6bf3dee7b..ffd042b4c52c2e7a6a967b69a87471a2e199e6ca 100644 (file)
@@ -24,10 +24,8 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
   /// 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<GeomAPI_Edge> line(std::shared_ptr<GeomAPI_Pnt> theStart,
-                                            std::shared_ptr<GeomAPI_Pnt> theEnd,
-                                            const bool theInfinite = false);
+                                            std::shared_ptr<GeomAPI_Pnt> theEnd);
   /// Creates edge - axis of the given cylindrical face. The result axis edge is infinite
   static std::shared_ptr<GeomAPI_Edge> cylinderAxis(
     std::shared_ptr<GeomAPI_Shape> theCylindricalFace);
index 9e687d6d296aa65d1b726313f7338747d5cecaab..46a46d233446b0a923c44dd605128f3e16f88105 100644 (file)
@@ -31,8 +31,7 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
 
 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
     std::shared_ptr<GeomAPI_Pln> thePlane,
-    const double theSize,
-    const bool theInfinite)
+    const double theSize)
 {
   // half of the size in each direction from the center
   BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
@@ -40,8 +39,6 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
                                        -theSize / 2., theSize / 2.);
   std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
   TopoDS_Shape aFace = aFaceBuilder.Face();
-  if (theInfinite)
-    aFace.Infinite(Standard_True);
   aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/));
   return aRes;
 }
index 7b68fadcbb3f8548e84170e7d3b578632e659ec2..49ec19c3084da7dea685cc74fd7bcfd497f60111 100644 (file)
@@ -30,8 +30,7 @@ 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<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pln> thePlane,
-                                               const double theSize,
-                                               const bool theInfinite = false);
+                                               const double theSize);
 
   /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
   static std::shared_ptr<GeomAPI_Pln> plane(std::shared_ptr<GeomAPI_Shape> theFace);
index 2a8893a7ea0de836b78b73d151bd5fb529094ae5..41e1a9b166a43771fac03ba55775eae2b17f9c5c 100644 (file)
@@ -46,6 +46,7 @@ Model_ResultConstruction::Model_ResultConstruction()
 {
   myIsDisabled = true; // by default it is not initialized and false to be after created
   myIsInHistory = true;
+  myIsInfinite = false;
   myFacesUpToDate = false;
   setIsConcealed(false);
 }
@@ -80,3 +81,13 @@ std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
 {
   return myFaces[theIndex];
 }
+
+bool Model_ResultConstruction::isInfinite()
+{
+  return myIsInfinite;
+}
+
+void Model_ResultConstruction::setInfinite(const bool theInfinite)
+{
+  myIsInfinite = theInfinite;
+}
index e5081240976388fbd85640eaff8013c29f05530a..ac07a4a6225f89995983c561fcd11e20e4180c51 100644 (file)
@@ -25,6 +25,7 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction
   bool myFacesUpToDate; ///< is true if faces in myuFaces are computed and up to date
   std::vector<std::shared_ptr<GeomAPI_Face> > myFaces; ///< stores the up to date faces if they exist
   bool myIsInHistory;
+  bool myIsInfinite;
  public:
   /// default color for a result construction
   inline static const std::string& DEFAULT_COLOR()
@@ -59,6 +60,11 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction
   /// if the construction result may be used as faces, this method returns face by zero based index
   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Face> face(const int theIndex);
 
+  /// By default object is not infinite.
+  MODEL_EXPORT virtual bool isInfinite();
+  /// Sets the flag that it is infinite
+  MODEL_EXPORT virtual void setInfinite(const bool theInfinite);
+
  protected:
   /// Makes a body on the given feature
   Model_ResultConstruction();
index 6040b35a599aded5b57267c02746a2632b79a6df..f24fb0d909a1ad387282367cf0b6c8b3c3df1d13 100644 (file)
@@ -43,6 +43,11 @@ class ModelAPI_ResultConstruction : public ModelAPI_Result
   virtual int facesNum() = 0;
   /// if the construction result may be used as faces, this method returns face by zero based index
   virtual std::shared_ptr<GeomAPI_Face> face(const int theIndex) = 0;
+
+  /// By default object is not infinite.
+  virtual bool isInfinite() = 0;
+  /// Sets the flag that it is infinite
+  virtual void setInfinite(const bool theInfinite) = 0;
 };
 
 //! Pointer on feature object
index 015701265747e0b6bd397b2a482c2bda04737861..3feadea09acb818fc002f474a9e88860ec8201c9 100755 (executable)
@@ -6,6 +6,10 @@
 
 #include "PartSet_FilterInfinite.h"
 
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ISelection.h>
+#include <ModelAPI_ResultConstruction.h>
+
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Shape.hxx>
 #include <TopoDS_Shape.hxx>
 IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
 
+PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
+: SelectMgr_Filter(), myWorkshop(theWorkshop)
+{
+}
+
 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()) {
-    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;
+
+  ModuleBase_ViewerPrs aPrs;
+  myWorkshop->selection()->fillPresentation(aPrs, theOwner);
+  ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
+  // to filter infinite construction results
+  if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
+    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+    if (aConstruction.get() && aConstruction->isInfinite()) {
+      Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+      if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
+        const TopoDS_Shape& aShape = aBRepOwner->Shape();
+        TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
+
+        TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
+        GeomShapePtr aResultShape = aResult->shape();
+        if (aResultShape.get()) {
+          TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
+          aResultShapeType = aResultTopoShape.ShapeType();
+        }
         // 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();
-          }
-        }
+        aValid = anOwnerShapeType == aResultShapeType;
       }
     }
   }
index 8fe53055b8f423b45b4423d4cb60fe2ffd5ea686..f6caa6666459f6196c8dbc6bd9d8e752660d0e11 100755 (executable)
@@ -11,6 +11,8 @@
 
 #include <SelectMgr_Filter.hxx>
 
+class ModuleBase_IWorkshop;
+
 /**
 * \class PartSet_FilterInfinite
 * \ingroup Modules
@@ -22,14 +24,17 @@ class PartSet_FilterInfinite : public SelectMgr_Filter
 public:
   /// Constructor
   /// \param theWorkshop a pointer to workshop
-  PartSet_FilterInfinite()
-    : SelectMgr_Filter() {}
+  PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop);
 
   /// Returns True if selected presentation can be selected
   /// \param theOwner an owner of the persentation
   Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
 
   DEFINE_STANDARD_RTTI(PartSet_FilterInfinite)
+
+protected:
+  /// Reference to workshop
+  ModuleBase_IWorkshop* myWorkshop;
 };
 
 #endif
\ No newline at end of file
index 6bbc85002567f16a820ddcc8205aae44eba53b1d..2be0fb9877bb8a8282c5511778292e6ca72d18af 100644 (file)
@@ -135,7 +135,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
 
   mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
-  mySelectionFilters.Append(new PartSet_FilterInfinite());
+  mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
 }
 
 PartSet_Module::~PartSet_Module()