]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Wed, 25 Jun 2014 07:14:11 +0000 (11:14 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 25 Jun 2014 07:14:11 +0000 (11:14 +0400)
1. Property panel input correction for a feature creation. It was not possible to perform "apply"
2. Creation opertion - do not allow to activate the next widget if the previous is not processed. Error: create arc, start lenght feature creation, select arc, the result is an editor control with the zero value inside.

src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/SketchPlugin/SketchPlugin_Arc.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_PropertyPanel.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index a15c0edcc299c0478c39a8ca66bb49b905f5cb86..cd56f06c363d259b3dbbfad4bdaafe1cd2b56da9 100644 (file)
@@ -4,6 +4,9 @@
 
 #include "ModuleBase_ModelWidget.h"
 
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Attribute.h>
+
 #include "Config_WidgetAPI.h"
 
 #include <QWidget>
@@ -14,6 +17,11 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_
   myAttributeID = theData ? theData->widgetId() : "";
 }
 
+bool ModuleBase_ModelWidget::isInitialized(FeaturePtr theFeature) const
+{
+  return theFeature->data()->attribute(attributeID())->isInitialized();
+}
+
 bool ModuleBase_ModelWidget::canFocusTo(const std::string& theAttributeName) const
 {
   return theAttributeName == attributeID();
index 4bb40e3628973a4bfc4e65f824ee70ad7c6814dd..78680ec3b6347d26ad6ca18d055d0111b25a9f3b 100644 (file)
@@ -36,6 +36,11 @@ public:
   /// Destructor
   virtual ~ModuleBase_ModelWidget() {};
 
+  /// Returns the state whether the attribute of the feature is initialized
+  /// \param theFeature a model feature to be checked
+  /// \return the boolean result
+  bool isInitialized(FeaturePtr theFeature) const;
+
   /// Saves the internal parameters to the given feature
   /// \param theFeature a model feature to be changed
   virtual bool storeValue(FeaturePtr theFeature) const = 0;
index ec146ba79352f4a3cf1a9e31ee2ea0244c7416a0..5b22f3face29eb2bd73c5150340e21611d237e30 100644 (file)
@@ -167,8 +167,10 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle
         isApplyed = setWidgetFeature(aFeature);
     }
   }
-  flushUpdated();
-  emit activateNextWidget(myActiveWidget);
+  if (isApplyed) {
+    flushUpdated();
+    emit activateNextWidget(myActiveWidget);
+  }
 }
 
 void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
index ed8d3be222a4874f54694d3ac2d7884ffe04347a..c0891d80d8b70e7ee4f293c53d0f7dff3f10f9e1 100644 (file)
@@ -43,42 +43,44 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Arc::preview()
     // compute a circle point in 3D view
     boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
       boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_CENTER));
-    boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
-    // make a visible point
-    boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
-    aShapes.push_back(aCenterPointShape);
-
-    // make a visible circle
-    boost::shared_ptr<GeomDataAPI_Dir> aNDir = 
-      boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
-    bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
-    if (aHasPlane) {
-      boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
       // compute the arc start point
       boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_START));
-      boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
-
-      // compute and change the arc end point
-      boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_END));
-      if (anEndAttr->isInitialized())
-      {
-        boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
-          new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
-        boost::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
-        if (aProjection && anEndAttr->pnt()->distance(aProjection) > Precision::Confusion())
-          anEndAttr->setValue(aProjection);
+      if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) {
+      boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+      // make a visible point
+      boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+      aShapes.push_back(aCenterPointShape);
+
+      // make a visible circle
+      boost::shared_ptr<GeomDataAPI_Dir> aNDir = 
+        boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
+      bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+      if (aHasPlane) {
+        boost::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+        boost::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+
+        // compute and change the arc end point
+        boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
+          boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(ARC_ATTR_END));
+        if (anEndAttr->isInitialized())
+        {
+          boost::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
+            new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
+          boost::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
+          if (aProjection && anEndAttr->pnt()->distance(aProjection) > Precision::Confusion())
+            anEndAttr->setValue(aProjection);
+        }
+        boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+
+        boost::shared_ptr<GeomAPI_Shape> aCircleShape = 
+                   GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal);
+        if (aCircleShape)
+          aShapes.push_back(aCircleShape);
       }
-      boost::shared_ptr<GeomAPI_Pnt> aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
-
-      boost::shared_ptr<GeomAPI_Shape> aCircleShape = 
-                 GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal);
-      if (aCircleShape)
-        aShapes.push_back(aCircleShape);
+      boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+      setPreview(aCompound);
     }
-    boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
-    setPreview(aCompound);
   }
   return getPreview();
 }
index 320678b1440769d1fbafef96d350a02f78a6066c..49faabba5d8014c4bca78b512bf68032355cb244 100644 (file)
@@ -117,12 +117,8 @@ bool XGUI_OperationMgr::canStopOperation()
 void XGUI_OperationMgr::onCommitOperation()
 {
   ModuleBase_Operation* anOperation = currentOperation();
-  if (anOperation) {
-    if (anOperation->canBeCommitted())
-      anOperation->commit();
-    else
-      anOperation->abort();
-  }
+  if (anOperation)
+    anOperation->commit();
 }
 
 void XGUI_OperationMgr::onAbortOperation()
index 54933b4b243af44dd2a25f1495654c8b5ec086b3..ae3df8179508b0c5b0a9284f4a6a2bce40888081 100644 (file)
@@ -122,6 +122,11 @@ void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& t
   }
 }
 
+const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
+{
+  return myWidgets;
+}
+
 bool XGUI_PropertyPanel::eventFilter(QObject *theObject, QEvent *theEvent)
 {
   QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
index 51155a481ebc3f88ecb28ef2030098c5d8c4e88d..764575dd89889451eeb7ed50205f3cb1c48541e3 100644 (file)
@@ -27,6 +27,7 @@ public:
 
   QWidget* contentWidget();
   void setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets);
+  const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
 
   void cleanContent();
 
index eb099c9b76254b7b9d4ed31ad5e973547a5cc1c0..3b5068dfab64fac7fff402303c1f37c4b7d74355 100644 (file)
@@ -322,7 +322,9 @@ void XGUI_Workshop::onOperationStarted()
     ModuleBase_ModelWidget* aWidget;
     for (; anIt != aLast; anIt++) {
       aWidget = *anIt;
-      QObject::connect(aWidget, SIGNAL(valuesChanged()),  aOperation, SLOT(storeCustomValue()));
+      //QObject::connect(aWidget, SIGNAL(valuesChanged()),  aOperation, SLOT(storeCustomValue()));
+      QObject::connect(aWidget, SIGNAL(valuesChanged()),
+                       this, SLOT(onWidgetValuesChanged()));
       // Init default values
       if (!aOperation->isEditOperation() && aWidget->hasDefaultValue()) {
         aWidget->storeValue(aOperation->feature());
@@ -823,6 +825,26 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     showFeatures(aFeatures, false);
 }
 
+//**************************************************************
+void XGUI_Workshop::onWidgetValuesChanged()
+{
+  ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+  FeaturePtr aFeature = anOperation->feature();
+
+  ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
+  //if (aCustom)
+  //  aCustom->storeValue(aFeature);
+
+  const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+  QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
+  for (; anIt != aLast; anIt++) {
+    ModuleBase_ModelWidget* aCustom = *anIt;
+    if (aCustom && (!aCustom->isInitialized(aFeature) || aCustom == aSenderWidget)) {
+      aCustom->storeValue(aFeature);
+    }
+  }
+}
+
 //**************************************************************
 void XGUI_Workshop::activatePart(FeaturePtr theFeature)
 {
index fba793e83cec553a386a6701e529b2a8a6873965..e52f48db8323d1b5b30fbb00d9c8b27ac2baccd1 100644 (file)
@@ -155,6 +155,8 @@ protected slots:
 
   void onContextMenuCommand(const QString& theId, bool isChecked);
 
+  void onWidgetValuesChanged();
+
 private:
   void initMenu();