]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of Fitter
authorvsv <vsv@opencascade.com>
Mon, 9 Sep 2019 15:26:56 +0000 (18:26 +0300)
committervsv <vsv@opencascade.com>
Mon, 9 Sep 2019 15:26:56 +0000 (18:26 +0300)
src/ModuleBase/ModuleBase_IViewer.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h

index c52c0d952907c43ee2e4a674413165f5714e3f51..825879490a387c63b1a17f6aa1386c9117d109ff 100644 (file)
@@ -21,6 +21,7 @@
 #define ModuleBase_IViewer_H
 
 #include "ModuleBase.h"
+
 #include <QObject>
 #include <QMap>
 #include <AIS_InteractiveContext.hxx>
index 1c4c03e07ac37eda0a63e73411c862524ba05dbe..1576ff0b1e61b4cae4b34ded6ec5295608ccc9ac 100644 (file)
@@ -1099,10 +1099,20 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
 
   workshop()->viewer()->set2dMode(true);
+
+  PartSet_Fitter* aFitter = new PartSet_Fitter(myCurrentSketch);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  aWorkshop->viewer()->setFitter(aFitter);
 }
 
 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 {
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  PartSet_Fitter* aFitter = (PartSet_Fitter*)aWorkshop->viewer()->currentFitter();
+  aWorkshop->viewer()->unsetFitter();
+  delete aFitter;
+
   myIsMouseOverWindow = false;
   myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
   myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
@@ -1114,8 +1124,6 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
   }
   onShowPoints(false);
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
-
   DataPtr aData = myCurrentSketch->data();
   if (!aData->isValid()) {
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
@@ -2100,3 +2108,28 @@ void PartSet_SketcherMgr::onShowPoints(bool toShow)
   if (aToUpdate)
     aViewer->update();
 }
+
+
+void PartSet_Fitter::fitScene(Handle(V3d_View) theView)
+{
+  Bnd_Box aBndBox;
+  int aNumberOfSubs = mySketch->numberOfSubs();
+  for (int i = 0; i < aNumberOfSubs; i++) {
+    FeaturePtr aFeature = mySketch->subFeature(i);
+    std::list<ResultPtr> aResults = aFeature->results();
+    std::list<ResultPtr>::const_iterator aIt;
+    ResultPtr aRes;
+    double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+    for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+      aRes = (*aIt);
+      if (aRes->isDisplayed()) {
+        GeomShapePtr aShape = aRes->shape();
+        aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+        Bnd_Box aBox;
+        aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+        aBndBox.Add(aBox);
+      }
+    }
+  }
+  theView->FitAll(aBndBox, 0.01);
+}
index 6dfe03cc25f850ba5aa564678d4b4aa82d6e008c..4920caa397ca69145f89b0ccc6c9f417398b62ca 100644 (file)
 
 #include <GeomAPI_Pln.h>
 
+#ifdef HAVE_SALOME
+  #include <OCCViewer_ViewModel.h>
+#else
+  #include <AppElements_Viewer.h>
+#endif
+
+
 #include <SelectMgr_IndexedMapOfOwner.hxx>
 #include <SelectMgr_ListOfFilter.hxx>
 
@@ -55,12 +62,34 @@ class ModuleBase_ModelWidget;
 class ModuleBase_Operation;
 class XGUI_OperationMgr;
 class XGUI_Workshop;
+class XGUI_Displayer;
 class PartSet_ExternalPointsMgr;
 
 class AIS_InteractiveObject;
 
 class QMouseEvent;
 
+
+#ifdef HAVE_SALOME
+class PartSet_Fitter : public OCCViewer_Fitter
+#else
+class PartSet_Fitter : public AppElements_Fitter
+#endif
+{
+public:
+  PartSet_Fitter(CompositeFeaturePtr theCurrentSketch):
+    mySketch(theCurrentSketch) {}
+
+  /// A method which has top be reimplemented to provide alterantive implementation FitAll command
+  /// \param theView - a view which has to be fit
+  virtual void fitScene(Handle(V3d_View) theView);
+
+private:
+  CompositeFeaturePtr mySketch;
+};
+
+
+
 /**
 * \ingroup Modules
 * A class for management of sketch operations
index 0523975fffdf12e70b31c72fc608c725eb6c8fa2..16fe9ee86b46e33a2cb58c0e425c9610547d696f 100644 (file)
@@ -723,4 +723,36 @@ void XGUI_ViewerProxy::setupColorScale()
 //      aView3d->DepthFitAll();
 //  }
 //#endif
-//}
\ No newline at end of file
+//}
+
+
+#ifdef HAVE_SALOME
+void XGUI_ViewerProxy::setFitter(OCCViewer_Fitter* theFitter)
+{
+  myWorkshop->salomeConnector()->viewer()->setFitter(theFitter);
+}
+
+OCCViewer_Fitter* XGUI_ViewerProxy::currentFitter() const
+{
+  return myWorkshop->salomeConnector()->viewer()->currentFitter();
+}
+#else
+void XGUI_ViewerProxy::setFitter(AppElements_Fitter* theFitter)
+{
+  myWorkshop->mainWindow()->viewer()->setFitter(theFitter);
+}
+
+AppElements_Fitter* XGUI_ViewerProxy::currentFitter() const
+{
+  return myWorkshop->mainWindow()->viewer()->currentFitter();
+}
+#endif
+
+void XGUI_ViewerProxy::unsetFitter()
+{
+#ifdef HAVE_SALOME
+  myWorkshop->salomeConnector()->viewer()->unsetFitter();
+#else
+  myWorkshop->mainWindow()->viewer()->unsetFitter();
+#endif
+}
index bb3a445d5ddc6f6fa97a81e6232221c8bcc3bc35..d87e4fcfaa3a67274d7e3af3fa74cfdadd20862c 100644 (file)
 #include <AIS_Trihedron.hxx>
 #include <AIS_ListOfInteractive.hxx>
 
-#ifndef HAVE_SALOME
+#ifdef HAVE_SALOME
+#include <OCCViewer_ViewModel.h>
+#else
+  #include <AppElements_Viewer.h>
   #include <AppElements_ViewWindow.h>
 #endif
 
+
+
 class XGUI_Workshop;
 /**
  * \ingroup GUI
@@ -164,6 +169,16 @@ Q_OBJECT
   // Fit all along Z (perpendicular to display)
   //virtual void Zfitall();
 
+#ifdef HAVE_SALOME
+  void setFitter(OCCViewer_Fitter* theFitter);
+  OCCViewer_Fitter* currentFitter() const;
+#else
+  void setFitter(AppElements_Fitter* theFitter);
+  AppElements_Fitter* currentFitter() const;
+#endif
+
+  void unsetFitter();
+
 signals:
   /// Emits by mouse entering the view port
   void enterViewPort();