]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 14:07:46 +0000 (18:07 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 14:07:46 +0000 (18:07 +0400)
Set plane for sketch and erase the sketch preview.

src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_Workshop.cpp

index 260da21aa23d88a18d2849ad6bcacbab6b84d112..45abe7d5b1bd5e631848ec3971b2272e4b592e70 100644 (file)
@@ -47,6 +47,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI
                     ${CMAKE_SOURCE_DIR}/src/Events
                     ${CMAKE_SOURCE_DIR}/src/ModuleBase
                     ${CMAKE_SOURCE_DIR}/src/ModelAPI
+                    ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
                     ${CMAKE_SOURCE_DIR}/src/SketchPlugin
                     ${CMAKE_SOURCE_DIR}/src/GeomAPI
                     ${CAS_INCLUDE_DIRS}
@@ -62,7 +63,7 @@ ADD_LIBRARY(PartSet SHARED
 )
 
 # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore
-TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI)
+TARGET_LINK_LIBRARIES(PartSet ${PROJECT_LIBRARIES} XGUI ModelAPI GeomAlgoAPI)
 
 ADD_DEPENDENCIES(PartSet ModuleBase)
 
index e0d4d32b9aa6db345a548dfd564f15560cfe453d..f1787442a8740740b86d669d48e7133e183fcbfc 100644 (file)
@@ -119,9 +119,9 @@ void PartSet_Module::onViewSelectionChanged()
   if (aPreviewOp) {
     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
     if (aViewer) {
-      AIS_ListOfInteractive aList;
-      aViewer->getSelectedObjects(aList);
-      aPreviewOp->setSelectedObjects(aList);
+      NCollection_List<TopoDS_Shape> aList;
+      aViewer->getSelectedShapes(aList);
+      aPreviewOp->setSelectedShapes(aList);
     }
   }
 }
@@ -142,6 +142,6 @@ void PartSet_Module::visualizePreview(bool isDisplay)
   }
   else {
     myWorkshop->displayer()->GlobalSelection(false);
-    myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
+    myWorkshop->displayer()->Erase(anOperation->feature());
   }
 }
index c9608cd2e1982d8536a3d49b45da62d9d528897f..1f1f1e91c868e922ad5955e49cc21f5878c3c6f7 100644 (file)
@@ -4,9 +4,10 @@
 
 #include <PartSet_OperationSketch.h>
 
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
 #include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <AIS_Shape.hxx>
 #include <AIS_ListOfInteractive.hxx>
@@ -37,27 +38,32 @@ int PartSet_OperationSketch::getSelectionMode() const
   return TopAbs_FACE;
 }
 
-void PartSet_OperationSketch::setSelectedObjects(const AIS_ListOfInteractive& theList)
+void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
 {
   if (theList.IsEmpty())
     return;
 
-  // 1. get selected fase
-  Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(theList.First());
-  if (anAISShape.IsNull())
-    return;
-
-  const TopoDS_Shape& aShape = anAISShape->Shape();
-  boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
-  aRes->setImpl(new TopoDS_Shape(aShape));
+  // get selected shape
+  const TopoDS_Shape& aShape = theList.First();
+  boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+  aGShape->setImpl(new TopoDS_Shape(aShape));
 
   // get plane parameters
-  double anX = 1, anY = 0, aZ = 0, anOrigin = 0;
+  boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
 
   // set plane parameters to feature
-  //boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-  //boost::shared_ptr<ModelAPI_AttributeDocRef> anAttr = aData->docRef(SKETCH_ATTR_X);
-  //anAttr->setValue(anX);
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  double anA, aB, aC, aD;
+  aPlane->coefficients(anA, aB, aC, aD);
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+
+  aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
+  aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
+  aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
+  aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
+
+  //emit viewPlaneChanged();
 
   commit();
 }
index 83be57a998259b46d5f91f16a8bb88bf2e614e74..6a7670b0007caf3a9927899b9c279331328428fb 100644 (file)
@@ -33,8 +33,8 @@ public:
   virtual int getSelectionMode() const;
 
   /// Gives the current selected objects to be processed by the operation
-  /// \param theList a list of interactive selected objects
-  virtual void setSelectedObjects(const AIS_ListOfInteractive& theList);
+  /// \param theList a list of interactive selected shapes
+  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList);
 };
 
 #endif
index b6c160ae7de0870d30a4738ad66d52cde5038f77..72a635bb1c986ac5e701a0cba26decfedd0dd0d8 100644 (file)
@@ -8,12 +8,11 @@
 #include "PartSet.h"
 
 #include <TopoDS_Shape.hxx>
+#include <NCollection_List.hxx>
 
 #include <ModuleBase_PropPanelOperation.h>
 #include <QObject>
 
-class AIS_ListOfInteractive;
-
 /*!
   \class PartSet_OperationSketchBase
   * \brief The base operation for the sketch features.
@@ -39,7 +38,7 @@ public:
 
   /// Gives the current selected objects to be processed by the operation
   /// \param a list of interactive selected objects
-  virtual void setSelectedObjects(const AIS_ListOfInteractive& aList) = 0;
+  virtual void setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList) = 0;
 };
 
 #endif
index a036e8f7503f43064338e915fdbdcf9720503a93..bca8d2d24c37de2107155910d1d9fc51cca2d3a4 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_ListOfInteractive.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
 
 #include <AIS_Shape.hxx>
 
@@ -32,6 +33,13 @@ void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
 
   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
+  std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
+  if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
+    aDispAIS = myFeature2AISObjectMap[theFeature];
+  }
+  aDispAIS.push_back(anAIS);
+  myFeature2AISObjectMap[theFeature] = aDispAIS;
+
   aContext->Display(anAIS, Standard_False);
 
   if (isUpdateViewer)
@@ -39,10 +47,23 @@ void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
 }
 
 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           const TopoDS_Shape& theShape, const bool isUpdateViewer)
+                           const bool isUpdateViewer)
 {
+  if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
+    return;
+
+  std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
+  std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
+                                                             aLast = aDispAIS.end();
   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
-  aContext->EraseAll();
+  for (; anIt != aLast; anIt++) {
+    Handle(AIS_InteractiveObject) anAIS = *anIt;
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (anAISShape.IsNull())
+      continue;
+      aContext->Erase(anAISShape);
+  }
+
   if (isUpdateViewer)
     aContext->UpdateCurrentViewer();
 }
@@ -54,7 +75,14 @@ void XGUI_Displayer::LocalSelection(boost::shared_ptr<ModelAPI_Feature> theFeatu
   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
 
   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
+  std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
+  if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
+    aDispAIS = myFeature2AISObjectMap[theFeature];
+  }
+  aDispAIS.push_back(anAIS);
+  myFeature2AISObjectMap[theFeature] = aDispAIS;
   aContext->Display(anAIS, Standard_False);
+
   AIS_ListOfInteractive anAISList;
   anAISList.Append(anAIS);
   myViewer->setLocalSelection(anAISList, theMode, true);
index 1dc238b906be7046c02f67a4ae8552df01562110..2a54cb9e41b29a32e92fa9bcbce6a02669169bb6 100644 (file)
 #include <boost/shared_ptr.hpp>
 
 #include <TopoDS_Shape.hxx>
+#include <AIS_InteractiveObject.hxx>
+
+#include <map>
+#include <vector>
 
 class XGUI_Viewer;
 class ModelAPI_Feature;
 
+
 /**\class XGUI_Displayer
  * \ingroup GUI
  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
@@ -50,10 +55,8 @@ public:
 
   /// Erase the feature and a shape.
   /// \param theFeature a feature instance
-  /// \param theFeature a shape
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
-             const bool isUpdateViewer = true);
+  void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const bool isUpdateViewer = true);
 
   /// Deactivates selection of sub-shapes
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
@@ -61,6 +64,7 @@ public:
 
 protected:
   XGUI_Viewer* myViewer; ///< the viewer where the objects should be visualized
+  std::map<boost::shared_ptr<ModelAPI_Feature>, std::vector<Handle(AIS_InteractiveObject)> > myFeature2AISObjectMap;
 };
 
 #endif
index e6dd6e2b728597c75ae92e6fe7e4429a9b06c0f6..a09722bcdf66885aa8cb4f9a84f3d7a071457e32 100644 (file)
@@ -238,6 +238,17 @@ void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
     theList.Append(myAISContext->SelectedInteractive());
 }
 
+void XGUI_Viewer::getSelectedShapes(NCollection_List<TopoDS_Shape>& theList)
+{
+  Handle(AIS_InteractiveContext) ic = AISContext();
+
+  for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
+    TopoDS_Shape aShape = ic->SelectedShape();
+    if (!aShape.IsNull())
+      theList.Append(aShape);
+  }
+}
+
 void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
 {
   AIS_ListIteratorOfListOfInteractive aIt;
index c4ae363b613fefe6da0be570a3033a997c0026a7..c7a2492f1fda250990112f6ca7ab1f198113c146 100644 (file)
@@ -11,6 +11,8 @@
 #include <V3d_Viewer.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Trihedron.hxx>
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
 
 class XGUI_MainWindow;
 class QMdiSubWindow;
@@ -69,6 +71,10 @@ public:
   /// \param theList - list to be filled with selected objects
   void  getSelectedObjects(AIS_ListOfInteractive& theList);
 
+  /// Return shapes selected in 3D viewer
+  /// \param theList - list to be filled with selected shapes
+  void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
+
   /// Selects objects in 3D viewer. Other selected objects are left as selected
   /// \param theList - list objects to be selected
   void  setObjectsSelected(const AIS_ListOfInteractive& theList);
index f653683a1d478f76a4cdf8f3e438da33ab6dfd71..cbc3ce14610a781abcc743f987fb50b11f665ba3 100644 (file)
@@ -196,11 +196,18 @@ void XGUI_Workshop::onOperationStarted()
 //******************************************************
 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
 {
-  myMainWindow->hidePropertyPanel();
-  updateCommandStatus();
+  ModuleBase_PropPanelOperation* aOperation =
+        (ModuleBase_PropPanelOperation*)(myOperationMgr->currentOperation());
 
-  XGUI_MainMenu* aMenu = myMainWindow->menuObject();
-  aMenu->restoreCommandState();
+  if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+    updateCommandStatus();
+  } else {
+    myMainWindow->hidePropertyPanel();
+    updateCommandStatus();
+
+    XGUI_MainMenu* aMenu = myMainWindow->menuObject();
+    aMenu->restoreCommandState();
+  }
 }
 
 /*