]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
An attempt to realize the separation of VERTEX/EDGE/FACE for the modified attribute... BR_SKETCH_SHAPE_PLUGIN
authornds <nds@opencascade.com>
Fri, 18 Dec 2015 18:20:43 +0000 (21:20 +0300)
committernds <nds@opencascade.com>
Fri, 18 Dec 2015 18:20:43 +0000 (21:20 +0300)
The problem is that ::attributeChanged is called 1. too many times, 2. until shape is set in attribute selection (only object is set).

src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp
src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/SketchShapePlugin/SketchShapePlugin_Feature.cpp
src/SketchShapePlugin/SketchShapePlugin_Feature.h
src/SketchShapePlugin/SketchShapePlugin_PageGroupBox.cpp
src/SketchShapePlugin/plugin-SketchShape.xml

index 89d9356b9383908cf9f09eee98e71c51c0b2cd07..c6cea891172c10d2b1863eab21615da3c9f9ffa5 100755 (executable)
@@ -7,6 +7,8 @@
 #include <ModuleBase_WidgetCheckGroupBox.h>
 #include <ModelAPI_AttributeBoolean.h>
 
+#include <ModuleBase_WidgetFactory.h>
+
 #include <Config_WidgetAPI.h>
 #include <Config_Keywords.h>
 
@@ -25,10 +27,12 @@ ModuleBase_WidgetCheckGroupBox::ModuleBase_WidgetCheckGroupBox(QWidget* theParen
 {
   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
   bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
+  QString aGroupName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
 
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aMainLayout);
   myGroupBox = new QGroupBox(this);
+  myGroupBox->setTitle(aGroupName);
   myGroupBox->setCheckable(true);
   myGroupBox->setToolTip(aToolTip);
   myGroupBox->setChecked(isChecked);
@@ -46,11 +50,6 @@ ModuleBase_WidgetCheckGroupBox::~ModuleBase_WidgetCheckGroupBox()
 {
 }
 
-void ModuleBase_WidgetCheckGroupBox::setTitle(const QString& theTitle)
-{
-  myGroupBox->setTitle(theTitle);
-}
-
 QWidget* ModuleBase_WidgetCheckGroupBox::pageWidget()
 {
   return myGroupBox;
index 4d8c12a4122a8e0cfa12b31b2ce571a5b961199c..b276c68dd6a270a2c48d1c70f4edc209097f9ea3 100755 (executable)
@@ -31,8 +31,6 @@ public:
                                  const std::string& theParentId);
   virtual ~ModuleBase_WidgetCheckGroupBox();
 
-  void setTitle(const QString& theTitle);
-
   /// Methods to be redefined from ModuleBase_PageBase: start
   /// Cast the page to regular QWidget
   virtual QWidget* pageWidget();
index f32f0aca8dc7ce29cba19c7777daedfb0be209b5..1d8b6c07327c6190703a90d969fb434571307666 100644 (file)
@@ -133,10 +133,8 @@ ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::strin
     aResult = aPage;
   }
   else if (theType == WDG_CHECK_GROUP) {
-    QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
     ModuleBase_WidgetCheckGroupBox* aPage = new ModuleBase_WidgetCheckGroupBox(theParent,
                                                                 myWidgetApi, myParentId);
-    aPage->setTitle(aGroupName);
     aResult = aPage;
   }
   if (!aResult)
index 95dfd185fde18a941bfab9e8e5a3c1cc04ddb9e4..fe92347df58f80a9bc28481264283301d84e521a 100755 (executable)
@@ -113,6 +113,9 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str()
                                                       : tr("Selected objects:"), this);
   aMainLay->addWidget(aListLabel, 1, 0);
+  bool aUseListLabel = theData->getBooleanAttribute("use_label", true);
+  if (!aUseListLabel)
+    aListLabel->setVisible(false);
   // if the xml definition contains one type, an information label should be shown near to the latest
   if (aShapeTypes.size() <= 1) {
     QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
index 4de0c8de33f3a5e99516b8348288a5b06164e0f2..93f50ebe0ba9a7cd3821518869c33ae4ca2a5d97 100755 (executable)
@@ -14,7 +14,7 @@
 #include <ModelAPI_Validator.h>
 
 SketchShapePlugin_Feature::SketchShapePlugin_Feature()
-: ModelAPI_Feature()
+: ModelAPI_Feature(), myIsAttributeChangeBlocked(false)
 {
 }
 
@@ -41,6 +41,9 @@ void SketchShapePlugin_Feature::execute()
 
 void SketchShapePlugin_Feature::attributeChanged(const std::string& theID)
 {
+  if (myIsAttributeChangeBlocked)
+    return;
+
   if (theID == VERTEX_CHOICE_ID() ||
       theID == EDGE_CHOICE_ID() ||
       theID == FACE_CHOICE_ID()) {
@@ -51,25 +54,74 @@ void SketchShapePlugin_Feature::attributeChanged(const std::string& theID)
     AttributeBooleanPtr aChoiceAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
                                            data()->attribute(theID));
     if (!aChoiceAttribute->value()) {
-      AttributeSelectionListPtr aListAttribute =
-        std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->attribute(aListAttrId));
+      AttributeSelectionListPtr aListAttribute = data()->selectionList(aListAttrId);
       aListAttribute->clear();
     }
   }
   else if (theID == VERTEX_LIST_ID() ||
            theID == EDGE_LIST_ID() ||
            theID == FACE_LIST_ID()) {
-    AttributeSelectionListPtr aSelectionListAttr = 
-                      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->attribute(theID));
-    for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
-      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
-      ObjectPtr anObject = aSelectAttr->context();
+    myIsAttributeChangeBlocked = true;
+
+    DataPtr aData = data();
+    AttributeSelectionListPtr aChangedAttr = aData->selectionList(theID);
+
+    AttributeSelectionListPtr aVertexAttr = aData->selectionList(VERTEX_LIST_ID());
+    AttributeSelectionListPtr anEdgeAttr = aData->selectionList(EDGE_LIST_ID());
+    AttributeSelectionListPtr aFaceAttr = aData->selectionList(FACE_LIST_ID());
+
+    if (theID != VERTEX_LIST_ID())
+      aVertexAttr->clear();
+    if (theID != EDGE_LIST_ID())
+      anEdgeAttr->clear();
+    if (theID != FACE_LIST_ID())
+      aFaceAttr->clear();
+
+    std::list<std::pair<ResultPtr, GeomShapePtr> > aChangedAttrValues;
+    for (int i = 0, aSize = aChangedAttr->size(); i < aSize; i++) {
+      AttributeSelectionPtr aSelectAttr = aChangedAttr->value(i);
+      ResultPtr anObject = aSelectAttr->context();
       if (!anObject.get())
         continue;
       else {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+        GeomShapePtr aGeomShape = aSelectAttr->value();
+        if (aGeomShape.get() == NULL)
+          aGeomShape = anObject->shape();
+
+        if (aGeomShape.get() == NULL)
+          continue;
+
+        GeomAPI_Shape::ShapeType aShapeType = aGeomShape->shapeType();
+        if (aGeomShape->isVertex()) {
+          if (theID == VERTEX_LIST_ID())
+            aChangedAttrValues.push_back(std::make_pair(anObject, aGeomShape));
+          else {
+            aVertexAttr->append(anObject, aGeomShape);
+          }
+        }
+        else if (aGeomShape->isEdge()) {
+          if (theID == EDGE_LIST_ID())
+            aChangedAttrValues.push_back(std::make_pair(anObject, aGeomShape));
+          else {
+            anEdgeAttr->append(anObject, aGeomShape);
+          }
+        }
+        else if (aGeomShape->isFace()) {
+          if (theID == FACE_LIST_ID())
+            aChangedAttrValues.push_back(std::make_pair(anObject, aGeomShape));
+          else {
+            aFaceAttr->append(anObject, aGeomShape);
+          }
+        }
       }
     }
+    //aChangedAttr->clear();
+    std::list<std::pair<ResultPtr, GeomShapePtr> >::const_iterator anIt = aChangedAttrValues.begin(),
+                                                                   aLast = aChangedAttrValues.end();
+    for (; anIt != aLast; anIt++)
+      aChangedAttr->append((*anIt).first, (*anIt).second);
+
+    myIsAttributeChangeBlocked = false;
   }
 }
 
index 0a59da95d1fffd31f42279bbd3e22dff76720ccb..2add7c2312e532005e703d876647525e1a73801c 100755 (executable)
@@ -97,6 +97,9 @@ class SketchShapePlugin_Feature : public ModelAPI_Feature
 
   /// Use plugin manager for features creation
   SketchShapePlugin_Feature();
+
+protected:
+  bool myIsAttributeChangeBlocked; /// flag to do not apply attributeChanged functionality
 };
 
 #endif
index db4d9eb70196e51988369008798d03197492305e..e2f443e4472d9b129eb1a6a60870a33e5e4bdf13 100755 (executable)
@@ -6,6 +6,9 @@
 
 #include <SketchShapePlugin_PageGroupBox.h>
 
+#include <QListWidget>
+#include <QList>
+
 SketchShapePlugin_PageGroupBox::SketchShapePlugin_PageGroupBox(QWidget* theParent)
 : ModuleBase_PageGroupBox(theParent)
 {
@@ -13,6 +16,12 @@ SketchShapePlugin_PageGroupBox::SketchShapePlugin_PageGroupBox(QWidget* theParen
 
 void SketchShapePlugin_PageGroupBox::setHighlightedGroupBox(bool isHighlighted)
 {
-  ModuleBase_Tools::setShadowEffect(this, isHighlighted);
+  QList<QListWidget*> aListWidgets = findChildren<QListWidget*>();
+
+  QList<QListWidget*>::const_iterator anIt = aListWidgets.begin(), aLast = aListWidgets.end();
+  for (; anIt != aLast; anIt++) {
+    QListWidget* aListWidget = *anIt;
+    ModuleBase_Tools::setShadowEffect(aListWidget, isHighlighted);
+  }
 }
 
index ace539bf61857b5ed924877ba0cf11a5372080cc..e988883b6fed18bc2b05c5b28f5958df6c87c805 100755 (executable)
@@ -18,7 +18,8 @@
               tooltip="Select list of vertices"
               type_choice="Vertices Edges Faces"
               use_external="false"
-              use_choice="false">
+              use_choice="false"
+              use_label="false">
               <validator id="SketchShapePlugin_FeatureValidator" />
             </sketchshape_multi_selector>
           </sketchshape_check_groupbox>
@@ -28,7 +29,8 @@
               tooltip="Select list of edges"
               type_choice="Vertices Edges Faces"
               use_external="false"
-              use_choice="false">
+              use_choice="false"
+              use_label="false">
               <validator id="SketchShapePlugin_FeatureValidator" />
             </sketchshape_multi_selector>
           </sketchshape_check_groupbox>
@@ -38,7 +40,8 @@
               tooltip="Select list of faces"
               type_choice="Vertices Edges Faces"
               use_external="false"
-              use_choice="false">
+              use_choice="false"
+              use_label="false">
               <validator id="SketchShapePlugin_FeatureValidator" />
             </sketchshape_multi_selector>
           </sketchshape_check_groupbox>