]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
2.5. Select the point of a sketch entity must display the editing point panel
authornds <nds@opencascade.com>
Wed, 10 Feb 2016 14:53:52 +0000 (17:53 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:43 +0000 (17:04 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/SketchPlugin/SketchPlugin_SketchEntity.h
src/XGUI/XGUI_Workshop.cpp

index da7ed2b31372d0bbb0a0986d5500b691d0300dcc..75a962dad7abdc0608b485fc8273deb31ad0614a 100755 (executable)
@@ -15,6 +15,7 @@
 #include <QString>\r
 #include <QObject>\r
 #include <QMap>\r
+#include <QList>\r
 \r
 #include <string>\r
 #include <vector>\r
@@ -122,6 +123,13 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// It is called as on clearing of property panel as on filling with new widgets\r
   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}\r
 \r
+  /// Have an opportunity to create widgets for the current operation instead of standard creation in workshop\r
+  /// \param theOperation a started operation\r
+  /// \param theWidgets a list of created widgets\r
+  /// \return boolean result, false by default\r
+  virtual bool createWidgets(ModuleBase_Operation* theOperation,\r
+                             QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }\r
+\r
   //! Returns True if there are available Undos and there is not an active operation\r
   virtual bool canUndo() const;\r
 \r
@@ -262,11 +270,6 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   virtual AttributePtr findAttribute(const ObjectPtr& theObject,\r
                                      const GeomShapePtr& theGeomShape) = 0;\r
 \r
-  /// Returns color of the object\r
-  /// \param theObject a result of a feature object\r
-  /// \param theColor a vector of three values in [0, 255] range\r
-  virtual void getColor(const ObjectPtr& theObject, std::vector<int>& theColor) {}\r
-\r
   /// Returns XML information by the feature index\r
   /// \param theFeatureId a feature id\r
   /// \param theXmlCfg XML configuration\r
index 0bca512683ca6942182cf33af26e20ed38080ea2..45d6446cad7272f8db35a3ca2bf9b34948cc5fc4 100644 (file)
@@ -121,11 +121,44 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
   thePage->alignToTop();
 }
 
+void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage,
+                                            const std::string& theWidgetId)
+{
+  bool aFound = false;
+  moveToWidgetId(theWidgetId, aFound);
+  if (aFound) {
+    std::string aWdgType = myWidgetApi->widgetType();
+
+    // Create a ModelWidget
+    ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
+    if (aWidget) {
+      if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
+        thePage->addModelWidget(aWidget);
+      }
+      else {
+        aWidget->setVisible(false);
+      }
+    }
+  }
+  thePage->alignToTop();
+}
+
 void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theFeatureKind,
                                                  const std::string& theAttributeId,
                                                  std::string& theTitle)
 {
-  if (!theTitle.empty())
+  bool aFound = false;
+  moveToWidgetId(theAttributeId, aFound);
+  if (aFound) {
+    theTitle = QString::fromStdString(myWidgetApi->widgetLabel()).toStdString().c_str();
+    if (theTitle.empty())
+      theTitle = QString::fromStdString(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)).toStdString().c_str();
+  }
+}
+
+void ModuleBase_WidgetFactory::moveToWidgetId(const std::string& theWidgetId, bool& theFound)
+{
+  if (theFound)
     return;
 
   myParentId = myWidgetApi->widgetId();
@@ -136,28 +169,23 @@ void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theFeatureKi
     std::string aWdgType = myWidgetApi->widgetType();
     // Find title under PageGroup
     if (myWidgetApi->isGroupBoxWidget() ||
-        ModuleBase_WidgetCreatorFactory::get()->hasPageWidget(aWdgType)) {
-
-      getAttributeTitle(theFeatureKind, theAttributeId, theTitle);
-    else {
+      ModuleBase_WidgetCreatorFactory::get()->hasPageWidget(aWdgType)) {
+      moveToWidgetId(theWidgetId, theFound);
+    }
+    else {
       // Find title here
       std::string anAttributeId = myWidgetApi->widgetId();
-      if (anAttributeId == theAttributeId) {
-        theTitle = QString::fromStdString(myWidgetApi->widgetLabel()).toStdString().c_str();
-        if (theTitle.empty())
-          theTitle = QString::fromStdString(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)).toStdString().c_str();
-
-      }
-      if (myWidgetApi->isPagedWidget()) {
+      theFound = anAttributeId == theWidgetId;
+      if (!theFound && myWidgetApi->isPagedWidget()) {
         //If current widget is toolbox or switch-casebox then fetch all
         //it's pages recursively and setup into the widget.
         myWidgetApi->toChildWidget();
         do {
-          getAttributeTitle(theFeatureKind, theAttributeId, theTitle);
-        } while (myWidgetApi->toNextWidget() && theTitle.empty());
+          moveToWidgetId(theWidgetId, theFound);
+        } while (!theFound && myWidgetApi->toNextWidget());
       }
     }
-  } while (myWidgetApi->toNextWidget() && theTitle.empty());
+  } while (!theFound && myWidgetApi->toNextWidget());
 }
 
 ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType,
index f51f541fac81f8c9091281bc1d9c7a776fbdad27..fd416271ecd652c380da60843ea9e5600d3124cf 100644 (file)
@@ -38,9 +38,14 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
   virtual ~ModuleBase_WidgetFactory();
 
   /// Creates content widget for property panel
-  /// \param theParent a parent widget
-  void createWidget(ModuleBase_PageBase* theParent);
+  /// \param thePage a parent page
+  void createWidget(ModuleBase_PageBase* thePage);
 
+  /// Creates one widget for property panel for the widget with given index
+  /// \param theParent a parent widget
+  /// \param theWidgetId a widget index
+  void createWidget(ModuleBase_PageBase* thePage,
+                    const std::string& theWidgetId);
 
   /// Returns list of model widgets
   QList<ModuleBase_ModelWidget*> getModelWidgets() const
@@ -76,6 +81,12 @@ protected:
   /// \param theStdString is STD string
   static QString qs(const std::string& theStdString);
 
+  /// It updates internal config api to point in the structure to given id of widget
+  /// The method is recusive and it stops when the found flag is true
+  /// \param theWidgetId a widget id key value
+  /// \param theFound a flag about found windget and recursive search should be stopped
+  void moveToWidgetId(const std::string& theWidgetId, bool& theFound);
+
  private:
    /// API object for XML reading
   Config_WidgetAPI* myWidgetApi;
index e49ff2ce18881bf3b16dc84a8ef8fb2ce8da6ae7..aef61e704814ce2dae5edff3c17fe834c57688bf 100755 (executable)
@@ -37,6 +37,8 @@
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_OperationDescription.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -94,6 +96,7 @@
 #include <QMessageBox>
 #include <QMainWindow>
 #include <QLineEdit>
+#include <QString>
 
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomDataAPI_Dir.h>
@@ -250,9 +253,7 @@ void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
       // the selection is cleared after commit the create operation
       // in order to do not use the same selected objects in the restarted operation
       // for common behaviour, the selection is cleared even if the operation is not restarted
-      XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-      XGUI_Workshop* aWorkshop = aConnector->workshop();
-      aWorkshop->selector()->clearSelection();
+      getWorkshop()->selector()->clearSelection();
     }
   }
 }
@@ -420,9 +421,7 @@ void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
   myMenuMgr->grantedOperationIds(theOperation, theIds);
 
   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
-    XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-    XGUI_Workshop* aWorkshop = aConnector->workshop();
-
+    XGUI_Workshop* aWorkshop = getWorkshop();
     theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
   }
 }
@@ -448,8 +447,7 @@ void PartSet_Module::clearViewer()
 {
   myCustomPrs->clearPrs();
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Workshop* aWorkshop = getWorkshop();
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
   aDisplayer->deactivateSelectionFilters();
 }
@@ -466,6 +464,44 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
     aPanel->activateWidget(aPanel->modelWidgets().first());
 }
 
+bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
+                                   QList<ModuleBase_ModelWidget*>& theWidgets) const
+{
+  bool aProcessed = false;
+
+  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+  XGUI_Workshop* aWorkshop = getWorkshop();
+  XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
+  if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
+    ModuleBase_ISelection* aSelection = workshop()->selection();
+    // click on a point in sketch leads here with the point is highlighted, not yet selected
+    QList<ModuleBase_ViewerPrs> aPreselection = aSelection->getHighlighted();
+    if (aPreselection.size() == 1) {
+      ModuleBase_ViewerPrs aSelectedPrs = aPreselection[0];
+      ObjectPtr anObject = aSelectedPrs.object();
+
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      FeaturePtr anOpFeature = aFOperation->feature();
+      TopoDS_Shape aShape = aSelectedPrs.shape();
+      // click on the digit of dimension constrain comes here with an empty shape, so we need the check
+      if (aFeature == anOpFeature && !aShape.IsNull()) {
+        AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aShape,
+                                                                         mySketchMgr->activeSketch());
+        if (anAttribute.get()) {
+          QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
+          ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
+
+          const std::string anAttributeId = anAttribute->id();
+          aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
+
+          theWidgets = aFactory.getModelWidgets();
+          aProcessed = true;
+        }
+      }
+    }
+  }
+  return aProcessed;
+}
 
 void PartSet_Module::onSelectionChanged()
 {
@@ -518,8 +554,7 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
 {
   ModuleBase_IWorkshop* aWorkshop = workshop();
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
-  XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
+  XGUI_Workshop* aXUIWorkshop = getWorkshop();
   ModuleBase_ModelWidget* aWgt = NULL;
   if (theType == "sketch-start-label") {
     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
@@ -588,8 +623,7 @@ bool PartSet_Module::deleteObjects()
 {
   bool isProcessed = false;
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Workshop* aWorkshop = getWorkshop();
   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
 
   //SessionPtr aMgr = ModelAPI_Session::get();
@@ -725,8 +759,7 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
 
   //Handle(V3d_View) aView = aViewer->activeView();
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Workshop* aWorkshop = getWorkshop();
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
   Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
   Handle(V3d_View) aView;
@@ -787,8 +820,7 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
   if (theResult.get())
     return aCustomized;
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Workshop* aWorkshop = getWorkshop();
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
   ObjectPtr anObject = aDisplayer->getObject(thePrs);
   if (anObject.get()) {
@@ -858,8 +890,7 @@ void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
   SessionPtr aMgr = ModelAPI_Session::get();
   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Workshop* aWorkshop = getWorkshop();
   QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
 
   aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
@@ -959,8 +990,7 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
     if (myWorkshop->currentOperation() && 
       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
       return;
-    XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-    XGUI_Workshop* aWorkshop = aConnector->workshop();
+    XGUI_Workshop* aWorkshop = getWorkshop();
     XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
     QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
     QPalette aPalet = aLabel->palette();
@@ -1004,8 +1034,7 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
   if (theIndex.column() != 0) // Use only first column
     return;
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_Workshop* aWorkshop = getWorkshop();
   XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
   // De not use non editable Indexes
   if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
@@ -1126,14 +1155,6 @@ AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
   return anAttribute;
 }
 
-//******************************************************
-void PartSet_Module::getColor(const ObjectPtr& theObject, std::vector<int>& theColor)
-{
-  if (myOverconstraintListener->isConflictingObject(theObject)) {
-    myOverconstraintListener->getConflictingColor(theColor);
-  }
-}
-
 //******************************************************
 void PartSet_Module::onBooleanOperationChange(int theOperation)
 {
@@ -1153,3 +1174,10 @@ void PartSet_Module::onBooleanOperationChange(int theOperation)
     break;
   }
 }
+
+//******************************************************
+XGUI_Workshop* PartSet_Module::getWorkshop() const
+{
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+  return aConnector->workshop();
+}
index 3cf93537c29ecae7a909299b48c0f8856ee9d907..f6c371f1f13cce9a5b495d52647b5ba2518d5df9 100755 (executable)
@@ -30,6 +30,7 @@
 
 class ModuleBase_Operation;
 class ModuleBase_IViewWindow;
+class XGUI_Workshop;
 class PartSet_MenuMgr;
 class PartSet_CustomPrs;
 class PartSet_SketcherMgr;
@@ -76,6 +77,14 @@ public:
   /// Call back forlast tuning of property panel before operation performance
   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
 
+  /// If there is found selected attribute, widgets are created and contains only a widget for the attribute
+  /// It is important for Property Panel filling by sketch point attribute
+  /// \param theOperation a started operation
+  /// \param theWidgets a list of created widgets
+  /// \return boolean result, false by default
+  virtual bool createWidgets(ModuleBase_Operation* theOperation,
+                             QList<ModuleBase_ModelWidget*>& theWidgets) const;
+
   /// Creates an operation and send it to loop
   /// \param theCmdId the operation name
   virtual void launchOperation(const QString& theCmdId);
@@ -268,11 +277,6 @@ public:
   /// \return theAttribute
   virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
 
-  /// Returns color of the object
-  /// \param theObject a result of a feature object
-  /// \param theColor a vector of three values in [0, 255] range
-  virtual void getColor(const ObjectPtr& theObject, std::vector<int>& theColor);
-
 public slots:
   /// Redefines the parent method in order to customize the next case:
   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
@@ -338,6 +342,9 @@ protected:
   //! Delete features
   virtual bool deleteObjects();
 
+  /// Returns the workshop
+  XGUI_Workshop* getWorkshop() const;
+
  private:
   SelectMgr_ListOfFilter mySelectionFilters;
 
index 58ac7eb9a55b4cd7f0e4a7c98e118fde70ebdd45..20f1e46f732205e98545e914308135dc613ef898 100644 (file)
@@ -23,7 +23,7 @@
 #define SKETCH_ENTITY_COLOR "225,0,0"
 #define SKETCH_EXTERNAL_COLOR "170,0,225"
 #define SKETCH_AUXILIARY_COLOR "0,85,0"
-#define SKETCH_OVERCONSTRAINT_COLOR "255,0,0"
+#define SKETCH_OVERCONSTRAINT_COLOR "0,0,0"
 
 /**\class SketchPlugin_SketchEntity
  * \ingroup Plugins
index 9d9b893001d59dae2021650deb8c3b37e7e8ad98..eebe7c38bc7354caad96142ce4e277105f1b7231 100755 (executable)
@@ -567,13 +567,15 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
     return;
 
   showPropertyPanel();
-  QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
-  ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
-
   myPropertyPanel->cleanContent();
-  aFactory.createWidget(myPropertyPanel->contentWidget());
 
-  QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
+  QList<ModuleBase_ModelWidget*> aWidgets;
+  if (!module()->createWidgets(theOperation, aWidgets)) {
+    QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
+    ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
+    aFactory.createWidget(myPropertyPanel->contentWidget());
+    aWidgets = aFactory.getModelWidgets();
+  }
 
   // check compatibility of feature and widgets
   FeaturePtr aFeature = aFOperation->feature();