]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make faces on selection of sketcher
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 22 Oct 2014 10:53:44 +0000 (14:53 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 22 Oct 2014 10:53:44 +0000 (14:53 +0400)
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h
src/XGUI/XGUI_Displayer.cpp

index a1ca0bdd94c2fc5f821d553c1807203a6d8f2d6c..c8eea52c22e4155eaab79d4322e32f145c23351d 100644 (file)
@@ -11,6 +11,7 @@
 #include <BRep_Builder.hxx>
 #include <AIS_Drawer.hxx>
 #include <Prs3d_IsoAspect.hxx>
+#include <TopoDS_Builder.hxx>
 
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
@@ -25,23 +26,12 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
     if (aWirePtr->hasPlane() ) {
       // If this is a wire with plane defined thin it is a sketch-like object
       // It must have invisible faces
-      std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
-        aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
+        aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList);
 
-      BRep_Builder aBuilder;
-      TopoDS_Shape aShape = aWirePtr->impl<TopoDS_Shape>();
-      std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
-      for (aIt = aFaces.cbegin(); aIt != aFaces.cend(); ++aIt) {
-        TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
-        aBuilder.Add(aShape, aFace);
-      }
-      Set(aShape);
+      myOriginalShape = aWirePtr->impl<TopoDS_Shape>();
+      Set(myOriginalShape);
       myIsSketchMode = true;
-      // Define number of ISO lines
-      //Handle(AIS_Drawer) aDrawer = Attributes();
-      //Attributes()->SetIsoOnPlane(Standard_False);
-      //SetAttributes(aDrawer);
     } else {
       Set(aWirePtr->impl<TopoDS_Shape>());
     }
@@ -51,24 +41,35 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
 }
 
 
-Standard_Boolean ModuleBase_ResultPrs::AcceptDisplayMode(const Standard_Integer theMode) const
-{
-  if (myIsSketchMode) {
-    return theMode == 0;
-  }
-  return AIS_Shape::AcceptDisplayMode(theMode);
-}
-
 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                                    const Handle(Prs3d_Presentation)& thePresentation, 
                                    const Standard_Integer theMode)
 {
-  if (myIsSketchMode) {
-    Handle(AIS_Drawer) aDrawer = Attributes();
-    aDrawer->SetIsoOnPlane(Standard_False);
-    aDrawer->UIsoAspect()->SetNumber(0);
-    aDrawer->VIsoAspect()->SetNumber(0);
-    SetAttributes(aDrawer);
-  }
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
+  myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
+  Set(aShapePtr->impl<TopoDS_Shape>());
   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 }
+
+
+void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+                                            const Standard_Integer aMode)
+{
+  if (myIsSketchMode) {
+    if (aMode == TopAbs_FACE) {
+      BRep_Builder aBuilder;
+      TopoDS_Compound aComp;
+      aBuilder.MakeCompound(aComp);
+      aBuilder.Add(aComp, myOriginalShape);
+      std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
+      for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
+        TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
+        aBuilder.Add(aComp, aFace);
+      }
+      Set(aComp);
+    } else {
+      Set(myOriginalShape);
+    }
+  }
+  AIS_Shape::ComputeSelection(aSelection, aMode);
+}
\ No newline at end of file
index 068cffe93cc8b0dfab8b4d60bec4ffa5f95eae12..0d2d058ce6540fefb7aa324a9b69464b50f311e5 100644 (file)
@@ -21,17 +21,21 @@ public:
 
   Standard_EXPORT ResultPtr getResult() const { return myResult; }
 
-  Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const;
-
   DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs)
 protected:
-  void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
     const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
 
+  Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+    const Standard_Integer aMode) ;
+
 private:
   ResultPtr myResult;
 
   bool myIsSketchMode;
+
+  TopoDS_Shape myOriginalShape;
+  std::list<boost::shared_ptr<GeomAPI_Shape> > myFacesList;
 };
 
 
index d281f86f08a1578ecea62c8aab33b82ee14ff660..736de32d2d7059deaafe0394e5b8e1d83f5cf0cd 100644 (file)
@@ -110,38 +110,27 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
   if (!isVisible(theObject))
     return;
 
-  Handle(AIS_InteractiveObject) aAISIO;
   AISObjectPtr aAISObj = getAISObject(theObject);
+  Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+
   GeomPresentablePtr aPrs = boost::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
   if (aPrs) {
     AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj);
-    if (aAISObj && !aAIS_Obj) {
+    if (!aAIS_Obj) {
       erase(theObject, isUpdateViewer);
       return;
     }
-    aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
-  } else {
-    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (aResult) {
-      boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-      if (aShapePtr) {
-        Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(
-            aAISObj->impl<Handle(AIS_InteractiveObject)>());
-        if (!aAISShape.IsNull()) {
-          aAISShape->Set(aShapePtr->impl<TopoDS_Shape>());
-          aAISIO = aAISShape;
-        }
-      }
+    if (aAIS_Obj != aAISObj) {
+      myResult2AISObjectMap[theObject] = aAIS_Obj;
     }
+    aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
   }
+
   if (!aAISIO.IsNull()) {
     Handle(AIS_InteractiveContext) aContext = AISContext();
     if (aContext.IsNull())
       return;
     aContext->Redisplay(aAISIO, isUpdateViewer);
-    //if (aContext->HasOpenedContext()) {
-    //  aContext->Load(aAISIO, -1, true/*allow decomposition*/);
-    //}
   }
 }