]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2204 Display a sketch plane - highlight only source plane, do not create wrapp...
authornds <nds@opencascade.com>
Tue, 3 Oct 2017 16:34:58 +0000 (19:34 +0300)
committernds <nds@opencascade.com>
Tue, 3 Oct 2017 16:34:58 +0000 (19:34 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_PreviewSketchPlane.cpp
src/PartSet/PartSet_PreviewSketchPlane.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_Workshop.cpp

index 8295af76172a7c2f6d3294b2463728ae3da1475a..995e21fe825269abddeb9dc26dd58b3356d839d3 100755 (executable)
@@ -309,9 +309,6 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// \param theStdActions - a map of standard actions
   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
 
-  /// Updates the current operation state after undo/redo actions calling
-  virtual void updateOperationByUndoRedo() {}
-
   /// Returns true if the action should be always enabled
   /// \param theActionId an action index: Accept or Accept All
   /// \return boolean value
index 078b18236f5a8c41be1d78d75f7890ca4e176f0d..282f82889d5d17f48ce890db8d10f880261c4185 100755 (executable)
@@ -550,12 +550,6 @@ void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActio
   myMenuMgr->updateViewerMenu(theStdActions);
 }
 
-void PartSet_Module::updateOperationByUndoRedo()
-{
-  PartSet_SketcherMgr* aSketchMgr = sketchMgr();
-  aSketchMgr->previewSketchPlane()->updatePlaneSize(aSketchMgr->activeSketch(), workshop());
-}
-
 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
 {
   bool isEnabledFixed = false;
index cc9bd9ed52e97e0b31e06b426f3ac15b72df542c..4a70c942f511760ce05a93907663a9707df3424b 100755 (executable)
@@ -331,9 +331,6 @@ public:
   /// \param theStdActions - a map of standard actions
   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
 
-  /// Updates the current operation state after undo/redo actions calling
-  virtual void updateOperationByUndoRedo();
-
   /// Returns true if the action should be always enabled
   /// \param theActionId an action index: Accept or Accept All
   /// \return boolean value
index 28b5c8491f5cf03ee865b7a0574c1af007350df9..bb60cc17da1c41587e76a9db972bdfa11a762bbe 100644 (file)
@@ -28,7 +28,7 @@
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Tools.h>
 
-#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAPI_AISObject.h>
 
 #include <XGUI_Tools.h>
 #include <XGUI_Displayer.h>
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_SketchEntity.h>
 
-#include <BRepBndLib.hxx>
-
-double maximumSize(double theXmin, double theYmin, double theZmin,
-                   double theXmax, double theYmax, double theZmax)
-{
-  double aSize = fabs(theXmax - theXmin);
-  double aSizeToCompare = fabs(theYmax - theYmin);
-  if (aSizeToCompare > aSize)
-    aSize = aSizeToCompare;
-  aSizeToCompare = fabs(theZmax - theZmin);
-  if (aSizeToCompare > aSize)
-    aSize = aSizeToCompare;
-
-  return aSize;
-}
-
 PartSet_PreviewSketchPlane::PartSet_PreviewSketchPlane()
- : mySketchDisplayed(false), myOtherSketchSize(0)
-{
-}
-
-void PartSet_PreviewSketchPlane::setOtherSketchParameters(const GeomShapePtr& theOtherSketchFace)
+ : myPreviewIsDisplayed(false)
 {
-  myOtherSketchOrigin = std::shared_ptr<GeomAPI_Pnt>();
-  myOtherSketchSize = 0;
-  if (!theOtherSketchFace)
-    return;
-
-  getShapeParameters(theOtherSketchFace, myOtherSketchOrigin, myOtherSketchSize);
 }
 
 void PartSet_PreviewSketchPlane::eraseSketchPlane(ModuleBase_IWorkshop* theWorkshop,
                                                   const bool isClearPlane)
 {
-  if (mySketchDisplayed) {
+  if (myPreviewIsDisplayed) {
     XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
     aDisp->eraseAIS(myPlane, false);
     if (isClearPlane) {
       myPlane = NULL;
-      myOrigin = NULL;
-      myNormal = NULL;
+      myShape = NULL;
     }
-    mySketchDisplayed = false;
+    myPreviewIsDisplayed = false;
   }
 }
 
 void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch,
                                                    ModuleBase_IWorkshop* theWorkshop)
 {
-  if (mySketchDisplayed)
+  // the preview plane has been already created and displayed
+  if (myPreviewIsDisplayed)
     return;
 
   // plane is visualized only if sketch plane is filled
-  std::shared_ptr<GeomAPI_Pln> aPlane = PartSet_Tools::sketchPlane(theSketch);
-  if (!aPlane.get())
+  if (!PartSet_Tools::sketchPlane(theSketch).get())
     return;
 
   if (!myPlane) { // If planes are not created
-    std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-        theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-    std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-        theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
     // Create Preview
-    // default planes parameters
-    std::shared_ptr<GeomAPI_Pnt> anOriginPnt = anOrigin->pnt();
-    double aSize = Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size");
-    // another sketch parameters
-    if (myOtherSketchOrigin) {
-      anOriginPnt = myOtherSketchOrigin;
-      aSize = myOtherSketchSize;
-      setOtherSketchParameters(GeomShapePtr());
-    }
-    else {
-      // selected linear face parameters
-      AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-        (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-      if (aSelAttr) {
-        std::shared_ptr<GeomAPI_Shape> aSketchExternalFace = aSelAttr->value();
-        if (aSketchExternalFace)
-          getShapeParameters(aSketchExternalFace, anOriginPnt, aSize);
-      }
+    // selected linear face parameters
+    AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+      (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+    if (aSelAttr)
+      myShape = aSelAttr->value();
+
+    if (!myShape.get()) {
+      // Create Preview for default planes
+      std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+          theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+      std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+          theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+      myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(),
+        Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size"));
     }
-    double aSketchSize = getSketchBoundingBoxSize(theSketch, anOriginPnt);
-    if (aSketchSize > 0)
-      aSize = aSketchSize;
-
-    myOrigin = anOriginPnt;
-    myNormal = aNormal->dir();
-    myPlane = createPreviewPlane(aSize);
+    myPlane = createPreviewPlane();
   }
 
   XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
   aDisp->displayAIS(myPlane, true, 1/*shaded*/, false);
-  mySketchDisplayed = true;
-}
-
-void PartSet_PreviewSketchPlane::updatePlaneSize(const CompositeFeaturePtr& theSketch,
-                                                 ModuleBase_IWorkshop* theWorkshop)
-{
-  std::shared_ptr<GeomAPI_Pnt> anOriginPnt;
-  double aSize = getSketchBoundingBoxSize(theSketch, anOriginPnt);
-  if (aSize <= 0)
-    return;
-  myOrigin = anOriginPnt;
-  createPreviewPlane(aSize);
+  myPreviewIsDisplayed = true;
 }
 
-AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane(double theSize)
+AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane()
 {
-  std::vector<int> aYZRGB(3, 0);
-#ifdef SET_PLANES_COLOR_IN_PREFERENCES
-    aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color");
-#else
-    aYZRGB[0] = 225;
-#endif
-    int aR[] = {aYZRGB[0], aYZRGB[1], aYZRGB[2]};
-
-  std::shared_ptr<GeomAPI_Shape> aFace =
-    GeomAlgoAPI_FaceBuilder::squareFace(myOrigin, myNormal, theSize);
-
   if (myPlane.get()) {
-    myPlane->createShape(aFace);
+    myPlane->createShape(myShape);
     return myPlane;
   }
   else {
     AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
-    aAIS->createShape(aFace);
+    aAIS->createShape(myShape);
     std::vector<int> aColor = Config_PropManager::color("Visualization", "sketch_preview_plane");
     if (aColor.size() == 3)
       aAIS->setColor(aColor[0], aColor[1], aColor[2]);
@@ -182,58 +118,3 @@ AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane(double theSize)
     return aAIS;
   }
 }
-
-void PartSet_PreviewSketchPlane::getShapeParameters(const GeomShapePtr& theShape,
-                                                    std::shared_ptr<GeomAPI_Pnt>& theOrigin,
-                                                    double& theSize)
-{
-  theOrigin = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
-
-  // Create rectangular face close to the selected
-  double aXmin, anYmin, aZmin, aXmax, anYmax, aZmax;
-  theShape->computeSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
-
-  theSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
-}
-
-double PartSet_PreviewSketchPlane::getSketchBoundingBoxSize(
-                                 const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
-                                 std::shared_ptr<GeomAPI_Pnt>& theCentralPnt)
-{
-  if (!theSketch.get() || theSketch->numberOfSubs() == 0)
-    return 0;
-
-  Bnd_Box aBox;
-  for (int aSubFeatureId = 0; aSubFeatureId < theSketch->numberOfSubs(); aSubFeatureId++) {
-    FeaturePtr aFeature = theSketch->subFeature(aSubFeatureId);
-    if (!aFeature.get())
-      continue;
-
-    std::list<ResultPtr> aResults = aFeature->results();
-    std::list<ResultPtr>::const_iterator aResultIt;
-    for (aResultIt = aResults.begin(); aResultIt != aResults.end(); ++aResultIt) {
-      ResultPtr aResult = *aResultIt;
-      std::shared_ptr<GeomAPI_Shape> aShapePtr = aResult->shape();
-      if (aShapePtr.get()) {
-        TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
-        if (aShape.IsNull())
-          continue;
-        BRepBndLib::Add(aShape, aBox);
-      }
-    }
-  }
-  if (aBox.IsVoid())
-    return 0;
-
-  double aXmin, aXmax, anYmin, anYmax, aZmin, aZmax;
-  aBox.Get(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
-
-  double aSize = maximumSize(aXmin, anYmin, aZmin, aXmax, anYmax, aZmax);
-  if (aSize > 0) {
-    gp_Pnt aCentre(aXmax-fabs(aXmax-aXmin)/2., anYmax-fabs(anYmax-anYmin)/2.,
-                   aZmax - fabs(aZmax-aZmin)/2.);
-    theCentralPnt = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(),
-                                                                 aCentre.Z()));
-  }
-  return aSize;
-}
\ No newline at end of file
index b2d32c84362b2933508d5914fe4aec6c019e43ae..11eabebd69e25b4f1cc49d5615e386120a56ad4e 100644 (file)
 #ifndef PartSet_PreviewSketchPlane_H
 #define PartSet_PreviewSketchPlane_H
 
-#include <GeomAPI_AISObject.h>
-
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Dir.h>
-#include <GeomAPI_AISObject.h>
+class GeomAPI_AISObject;
+class GeomAPI_Shape;
 
 class ModuleBase_IWorkshop;
 class ModelAPI_CompositeFeature;
 
+#include <memory>
+
 /**
 * \class PartSet_PreviewSketchPlane
 * \ingroup Modules
@@ -43,14 +42,6 @@ public:
 
   ~PartSet_PreviewSketchPlane() {};
 
-  /// Returns if the sketch plane was displayed
-  /// \return boolean value
-  bool isSketchDisplayed() const { return mySketchDisplayed; }
-
-  /// Sets parameters of another sketch to be used in createSketchPlane().
-  /// \param theOtherSketchFace a shape of other selected sketch. It is a planar face.
-  void setOtherSketchParameters(const std::shared_ptr<GeomAPI_Shape>& theOtherSketchFace);
-
   /// Erase preview planes
   /// \param theWorkshop the application workshop
   /// \param isClearPlane flag whether the plane, origin and normal should be nullified
@@ -62,40 +53,14 @@ public:
   void createSketchPlane(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
                          ModuleBase_IWorkshop* theWorkshop);
 
-  /// Resize plane size by sketch content
-  /// \param theSketch source sketch to build sketch sub features bounding box
-  /// \param theWorkshop the application workshop
-  void updatePlaneSize(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
-                       ModuleBase_IWorkshop* theWorkshop);
-
 private:
   /// Create a square face by parameters
-  /// \param theSize a size of created square
-  AISObjectPtr createPreviewPlane(double theSize);
-
-  /// Finds origin and maximum size of the shape
-  /// \param theShape source shape
-  /// \param theOrigin a shape center of mass
-  /// \param theSize maximum of delta X, Y or Z
-  void getShapeParameters(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                          std::shared_ptr<GeomAPI_Pnt>& theOrigin,
-                          double& theSize);
-
-  /// Calculate maximum bounding box size of sketch sub features
-  /// \param theSketch source sketch to build sketch sub features bounding box
-  /// \param theCentralPoint central point of the sketch sub features
-  /// \return double value
-  double getSketchBoundingBoxSize(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
-                                  std::shared_ptr<GeomAPI_Pnt>& theCentralPnt);
+  std::shared_ptr<GeomAPI_AISObject> createPreviewPlane();
 
 private:
-  bool mySketchDisplayed;
-  AISObjectPtr myPlane;
-  std::shared_ptr<GeomAPI_Pnt> myOrigin; //! an origin of the plane
-  std::shared_ptr<GeomAPI_Dir> myNormal; //! a normal vector of the plane
-
-  std::shared_ptr<GeomAPI_Pnt> myOtherSketchOrigin;
-  double myOtherSketchSize;
+  bool myPreviewIsDisplayed;
+  std::shared_ptr<GeomAPI_AISObject> myPlane; //! visualized presentation
+  std::shared_ptr<GeomAPI_Shape> myShape; //! current shape to be displayed
 };
 
 #endif
\ No newline at end of file
index 88334e9ee5b4eee569cb3c1b624283e4cf63e653..abaadd3119b5d3a25735baf406845eafc02354e0 100755 (executable)
@@ -1118,7 +1118,6 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
 
 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
 {
-  previewSketchPlane()->updatePlaneSize(activeSketch(), myModule->workshop());
   myIsMouseOverViewProcessed = true;
   operationMgr()->onValidateOperation();
   // when sketch nested operation is stopped the cursor should be restored unconditionally
index 8485a1b495d8923e36fa9636769f40f3df259a21..d3908d81e0e350937d88b90f512c7156dd2fe35d 100644 (file)
@@ -277,20 +277,6 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
 
   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
   if (aModule) {
-    // if selected object is a shape of another sketch, the origin of selected shape does not stored
-    // in argument, so we need to find parameters of selected shape on the sketch
-    if (thePrs->object() && (feature() != thePrs->object())) {
-      FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
-      if (aFeature.get() && (aFeature != feature())) {
-        if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
-          CompositeFeaturePtr aSketch =
-            std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
-          std::shared_ptr<GeomAPI_Pln> aPlane = PartSet_Tools::sketchPlane(aSketch);
-          if (aPlane.get())
-            aModule->sketchMgr()->previewSketchPlane()->setOtherSketchParameters(thePrs->shape());
-        }
-      }
-    }
     CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
     aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
   }
@@ -314,7 +300,8 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   // If the selected object is a sketch then use its plane
   std::shared_ptr<GeomAPI_Pln> aPlane;
   ObjectPtr aObj = thePrs->object();
-  if (aObj.get()) {
+  // obsolete as selected sketch is stored in external attribute
+  /*if (aObj.get()) {
     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
     if (aFeature.get() && (aFeature != feature())) {
       if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
@@ -323,7 +310,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
         aPlane = PartSet_Tools::sketchPlane(aSketch);
       }
     }
-  }
+  }*/
   if (aGShape.get() != NULL) {
     // get plane parameters
     if (!aPlane.get()) {
@@ -472,17 +459,6 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View
 
   if (thePrs->object() && (feature() != thePrs->object())) {
     FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
-    if (aFeature.get() && (aFeature != feature())) {
-      if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
-        CompositeFeaturePtr aSketch =
-          std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
-        std::shared_ptr<GeomAPI_Pln> aPlane = PartSet_Tools::sketchPlane(aSketch);
-        if (aPlane.get()) {
-          aDir = setSketchPlane(aPlane);
-          return aDir.get();
-        }
-      }
-    }
     DataPtr aData = feature()->data();
     AttributeSelectionPtr aSelAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
index 3c6073c7fd68bdff0969fcb490fadb99fafa6112..6abe0d130453c1908454cbc1f94cd3cb715357fa 100644 (file)
@@ -316,13 +316,6 @@ void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperati
   onValidateOperation();
 }
 
-void XGUI_OperationMgr::updateOperationByUndoRedo()
-{
-  ModuleBase_IModule* aModule = myWorkshop->module();
-  if (aModule)
-    aModule->updateOperationByUndoRedo();
-}
-
 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation,
                                          const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind)
 {
index b180436b3c53ab4fce86064f119c3864a4fab889..97cc7426c9b5896fd073f41720d09d00a4104274 100755 (executable)
@@ -181,9 +181,6 @@ public: // TEMPORARY, it should be protected and be performed automatically
   /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
   void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
 
-  /// Updates the current operation state after undo/redo actions calling
-  void updateOperationByUndoRedo();
-
 protected: // TEMPORARY
   /// Sets the current operation or NULL
   /// \param theOperation the started operation
index 05f7d43f2f213296f82028e370ba4283859206ed..7a11ee1bb221fce84b09df16ff07c921c5b6fce3 100755 (executable)
@@ -999,7 +999,6 @@ void XGUI_Workshop::onUndo(int theTimes)
   }
 
   operationMgr()->updateApplyOfOperations();
-  operationMgr()->updateOperationByUndoRedo();
   updateCommandStatus();
 }
 
@@ -1028,7 +1027,6 @@ void XGUI_Workshop::onRedo(int theTimes)
       myObjectBrowser->rebuildDataTree();
   }
   operationMgr()->updateApplyOfOperations();
-  operationMgr()->updateOperationByUndoRedo();
   updateCommandStatus();
 
   // unblock the viewer update functionality and make update on purpose