Salome HOME
Recover feature
authornds <nds@opencascade.com>
Fri, 29 Jul 2016 19:02:51 +0000 (22:02 +0300)
committernds <nds@opencascade.com>
Fri, 29 Jul 2016 19:02:51 +0000 (22:02 +0300)
src/Config/Config_Keywords.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_Recover.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Recover.h [new file with mode: 0644]
src/FeaturesPlugin/plugin-Features.xml
src/FeaturesPlugin/recover_widget.xml [new file with mode: 0644]
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetConcealedObjects.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetConcealedObjects.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFactory.cpp

index 43227a57103e35db29fa81198255c044049c64b7..adb9ae00c384baaeda63f59ada179faf3901e41f 100644 (file)
@@ -32,6 +32,7 @@ const static char* WDG_BOOLVALUE = "boolvalue";
 const static char* WDG_STRINGVALUE = "stringvalue";
 const static char* WDG_MULTISELECTOR = "multi_selector";
 const static char* WDG_SHAPE_SELECTOR = "shape_selector";
+const static char* WDG_CONCEALED_OBJECTS_VIEW = "concealed_objects_view";
 const static char* WDG_CHOICE = "choice";
 const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
 const static char* WDG_FILE_SELECTOR= "file_selector";
index 763e5138c491fa0465f63b90d54154b3b2be0c61..5b5ab88fe9ef95119e2332fe57c1c0598eafe245 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
     FeaturesPlugin.h
     FeaturesPlugin_Plugin.h
     FeaturesPlugin_Extrusion.h
+    FeaturesPlugin_Recover.h
     FeaturesPlugin_Revolution.h
     FeaturesPlugin_Rotation.h
     FeaturesPlugin_Translation.h
@@ -33,6 +34,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     FeaturesPlugin_Plugin.cpp
     FeaturesPlugin_Extrusion.cpp
+    FeaturesPlugin_Recover.cpp
     FeaturesPlugin_Revolution.cpp
     FeaturesPlugin_Rotation.cpp
     FeaturesPlugin_Translation.cpp
@@ -68,6 +70,7 @@ SET(XML_RESOURCES
   translation_widget.xml
   boolean_widget.xml
   group_widget.xml
+  recover_widget.xml
   partition_widget.xml
   placement_widget.xml
   intersection_widget.xml
index 54b0021f0a8bdaf51151f27e9aec857875a20381..0daaa1ec1fa1b9f94060e3da83c74d6233abc511 100644 (file)
@@ -12,6 +12,7 @@
 #include <FeaturesPlugin_Partition.h>
 #include <FeaturesPlugin_Pipe.h>
 #include <FeaturesPlugin_Placement.h>
+#include <FeaturesPlugin_Recover.h>
 #include <FeaturesPlugin_RemoveSubShapes.h>
 #include <FeaturesPlugin_Revolution.h>
 #include <FeaturesPlugin_RevolutionCut.h>
@@ -87,6 +88,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID)
     return FeaturePtr(new FeaturesPlugin_Pipe);
   } else if (theFeatureID == FeaturesPlugin_Placement::ID()) {
     return FeaturePtr(new FeaturesPlugin_Placement);
+  } else if (theFeatureID == FeaturesPlugin_Recover::ID()) {
+    return FeaturePtr(new FeaturesPlugin_Recover);
   } else if (theFeatureID == FeaturesPlugin_ExtrusionCut::ID()) {
     return FeaturePtr(new FeaturesPlugin_ExtrusionCut);
   } else if (theFeatureID == FeaturesPlugin_ExtrusionFuse::ID()) {
diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp
new file mode 100644 (file)
index 0000000..5eb5aa8
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        FeaturesPlugin_Recover.cpp
+// Created:     29 Jul 2016
+// Author:      Natalia ERMOLAEVA
+
+#include "FeaturesPlugin_Recover.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+using namespace std;
+
+FeaturesPlugin_Recover::FeaturesPlugin_Recover()
+{
+}
+
+void FeaturesPlugin_Recover::initAttributes()
+{
+  data()->addAttribute(BASE_SHAPE_ID(), ModelAPI_AttributeReference::typeId());
+  data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
+
+  /// temporary modification for empty list
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RECOVERED_ENTITIES());
+}
+
+void FeaturesPlugin_Recover::execute()
+{
+}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.h b/src/FeaturesPlugin/FeaturesPlugin_Recover.h
new file mode 100644 (file)
index 0000000..e24db88
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        FeaturesPlugin_Recover.h
+// Created:     29 Jul 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef FEATURESPLUGIN_RECOVER_H_
+#define FEATURESPLUGIN_RECOVER_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_Shape.h>
+
+/**\class FeaturesPlugin_Recover
+ * \ingroup Plugins
+ * \brief Feature for display of concealed attributes of some feature.
+ */
+class FeaturesPlugin_Recover : public ModelAPI_Feature
+{
+ public:
+  /// Extrusion kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_GROUP_ID("Recover");
+    return MY_GROUP_ID;
+  }
+  /// Attribute name of base shape.
+  inline static const std::string& BASE_SHAPE_ID()
+  {
+    static const std::string MY_BASE_SHAPE_ID("base_shape");
+    return MY_BASE_SHAPE_ID;
+  }
+
+  /// Attribute name of base shape.
+  inline static const std::string& RECOVERED_ENTITIES()
+  {
+    static const std::string MY_RECOVERED_ENTITIES_ID("recovered_entities");
+    return MY_RECOVERED_ENTITIES_ID;
+  }
+
+  /// Returns the kind of a feature
+  FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = FeaturesPlugin_Recover::ID();
+    return MY_KIND;
+  }
+
+  /// Creates a new part document if needed
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Use plugin manager for features creation
+  FeaturesPlugin_Recover();
+
+};
+
+#endif
index 6a5cba33d306b83fdd3032f5513a1e6af3eacf4e..98786b67b967aaa2462b0834159ae0e89a456492 100644 (file)
         <source path="group_widget.xml"/>
       </feature>
     </group>
+    <group id="Recover">
+      <feature id="Recover"
+        title="Recover"
+        tooltip="Visualize concealed objects"
+        icon="">
+        <source path="recover_widget.xml"/>
+      </feature>
+    </group>
   </workbench>
   <workbench id="Part">
     <group id="Movement">
diff --git a/src/FeaturesPlugin/recover_widget.xml b/src/FeaturesPlugin/recover_widget.xml
new file mode 100644 (file)
index 0000000..daf0d16
--- /dev/null
@@ -0,0 +1,12 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+  <shape_selector id="base_shape"
+                  label="Shape:"
+                  tooltip="Select a feature of concealed objects."
+                  shape_types="objects"/>
+  <concealed_objects_view id="recovered_entities"
+                  tooltip="Concealed objects"
+                  base_shape_attribute="base_shape"
+                  obligatory="0"/>
+</source>
\ No newline at end of file
index 8dd3b5de7af7af56363a5886f799e563b9e61e30..74a7932069e56aa579568a192c95016c0bd25ab5 100644 (file)
@@ -43,6 +43,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetAction.h
   ModuleBase_WidgetBoolValue.h
   ModuleBase_WidgetChoice.h
+  ModuleBase_WidgetConcealedObjects.h
   ModuleBase_WidgetCreatorFactory.h
   ModuleBase_WidgetDoubleValue.h
   ModuleBase_WidgetEditor.h
@@ -102,6 +103,7 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetAction.cpp
   ModuleBase_WidgetBoolValue.cpp
   ModuleBase_WidgetChoice.cpp
+  ModuleBase_WidgetConcealedObjects.cpp
   ModuleBase_WidgetCreatorFactory.cpp
   ModuleBase_WidgetDoubleValue.cpp
   ModuleBase_WidgetEditor.cpp
diff --git a/src/ModuleBase/ModuleBase_WidgetConcealedObjects.cpp b/src/ModuleBase/ModuleBase_WidgetConcealedObjects.cpp
new file mode 100644 (file)
index 0000000..ba83b77
--- /dev/null
@@ -0,0 +1,131 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_WidgetConcealedObjects.cpp
+// Created:     29 Jul 2016
+// Author:      Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetConcealedObjects.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_Result.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QGridLayout>
+#include <QCheckBox>
+
+#include <QWidget>
+#include <QTableWidget>
+#include <QHeaderView>
+
+ModuleBase_WidgetConcealedObjects::ModuleBase_WidgetConcealedObjects(QWidget* theParent,
+                                                     const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+  myBaseShapeAttribute = theData->getProperty("base_shape_attribute");
+  QGridLayout* aMainLay = new QGridLayout(this);
+  ModuleBase_Tools::adjustMargins(aMainLay);
+
+  myView = new QTableWidget(this);
+  aMainLay->addWidget(myView);
+
+  myView->setColumnCount(2);
+  myView->horizontalHeader()->setVisible(false);
+  myView->verticalHeader()->setVisible(false);
+}
+
+ModuleBase_WidgetConcealedObjects::~ModuleBase_WidgetConcealedObjects()
+{
+}
+
+bool ModuleBase_WidgetConcealedObjects::storeValueCustom()
+{
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
+  anAttributeList->clear();
+  int aSize1 = anAttributeList->size(false);
+  for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
+    QCheckBox* aButton = dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0));
+    if (aButton->isChecked())
+      anAttributeList->append(myConcealedResults[i]);
+  }
+  int aSize = anAttributeList->size(false);
+  return true;
+}
+
+bool ModuleBase_WidgetConcealedObjects::restoreValueCustom()
+{
+  FeaturePtr aBaseFeature;
+  ObjectPtr anObject;
+  if (myFeature) {
+    anObject = ModuleBase_Tools::getObject(myFeature->attribute(myBaseShapeAttribute));
+    if (anObject.get() != NULL)
+      aBaseFeature = ModelAPI_Feature::feature(anObject);
+  }
+  if (myBaseFeature != aBaseFeature) {
+    myView->setRowCount(0);
+    myConcealedResults.clear();
+    myBaseFeature = aBaseFeature;
+    if (myBaseFeature.get()) {
+      std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > > aRefs;
+      myBaseFeature->data()->referencesToObjects(aRefs);
+      std::list<std::pair<std::string, std::list<ObjectPtr> > >::const_iterator
+                                                      anIt = aRefs.begin(), aLast = aRefs.end();
+      for (; anIt != aLast; anIt++) {
+        std::list<ObjectPtr> anObjects = (*anIt).second;
+        std::list<ObjectPtr>::const_iterator anOIt = anObjects.begin(), anOLast = anObjects.end();
+        for (; anOIt != anOLast; anOIt++) {
+          ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*anOIt);
+          if (aResult->isConcealed()) {
+            int aRowId = myView->rowCount();
+            addViewRow(aResult);
+            myConcealedResults[aRowId] = aResult;
+          }
+        }
+      }
+    }
+  }
+  
+  DataPtr aData = myFeature->data();
+  AttributeRefListPtr anAttributeList = aData->reflist(attributeID());
+  int aSize = anAttributeList->size();
+  for (int i = 0, aSize = myView->rowCount(); i < aSize; i++) {
+    ResultPtr aResult = myConcealedResults[i];
+    QCheckBox* aButton = dynamic_cast<QCheckBox*>(myView->cellWidget(i, 0));
+    bool isChecked = anAttributeList->isInList(aResult);
+
+    bool aBlocked = aButton->blockSignals(true);
+    aButton->setChecked(isChecked);
+    aButton->blockSignals(aBlocked);
+  }
+  return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetConcealedObjects::getControls() const
+{
+  QList<QWidget*> result;
+  result << myView;
+  return result;
+}
+
+void ModuleBase_WidgetConcealedObjects::addViewRow(const std::shared_ptr<ModelAPI_Result>& theResult)
+{
+  int anId = myView->rowCount();
+  myView->setRowCount(anId+1);
+
+  QCheckBox* aVisibilityBox = new QCheckBox(this);
+  connect(aVisibilityBox, SIGNAL(toggled(bool)), this, SLOT(onItemToggled(bool)));
+  aVisibilityBox->setChecked(false);
+  myView->setCellWidget(anId, 0, aVisibilityBox);
+  myView->setItem(anId, 1, new QTableWidgetItem(theResult->data()->name().c_str()));
+}
+
+void ModuleBase_WidgetConcealedObjects::onItemToggled(bool theState)
+{
+  emit valuesChanged();
+  updateObject(myFeature);
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetConcealedObjects.h b/src/ModuleBase/ModuleBase_WidgetConcealedObjects.h
new file mode 100644 (file)
index 0000000..b289d7a
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_WidgetConcealedObjects.h
+// Created:     29 Jul 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef MODULEBASE_WIDGETCONCEALEDOBJECTS_H_
+#define MODULEBASE_WIDGETCONCEALEDOBJECTS_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <string>
+#include <map>
+#include <memory>
+
+class ModelAPI_Object;
+
+class QWidget;
+class QTableWidget;
+
+/**
+* \ingroup GUI
+* Implementation of model widget for table of concealed objects.
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetConcealedObjects : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuration.
+  ModuleBase_WidgetConcealedObjects(QWidget* theParent,
+                                    const Config_WidgetAPI* theData);
+  virtual ~ModuleBase_WidgetConcealedObjects();
+
+  /// Redefinition of virtual method
+  virtual QList<QWidget*> getControls() const;
+
+  /// The widget can not accept focus
+  virtual bool canAcceptFocus() const { return false; };
+
+protected:
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom();
+
+  /// Redefinition of virtual method
+  virtual bool restoreValueCustom();
+
+private:
+  /// Creates a row in view
+  /// \param theResult a result for the row
+  void addViewRow(const std::shared_ptr<ModelAPI_Result>& theResult);
+
+private slots:
+  /// Processes the display button click in the view.
+  /// \param theState a new state
+  void onItemToggled(bool theState);
+
+private:
+  std::string myBaseShapeAttribute; ///< attribute of the base object
+  QTableWidget* myView; ///< table view of visibility states
+
+  std::shared_ptr<ModelAPI_Feature> myBaseFeature; ///< backup of feature of filling the table view
+  /// backup of visualized in the view concealed objects, stored to avoid table rebuild by restore
+  std::map<int, std::shared_ptr<ModelAPI_Result> > myConcealedResults;
+};
+
+#endif /* MODULEBASE_WIDGETCONCEALEDOBJECTS_H_ */
index a33522dee055699c0615756a2b186f1a509f689e..8af4cbb32ac0d5bf5a511a9650ee0883e80dde7d 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_WidgetLineEdit.h>
 #include <ModuleBase_WidgetMultiSelector.h>
+#include <ModuleBase_WidgetConcealedObjects.h>
 #include <ModuleBase_WidgetLabel.h>
 #include <ModuleBase_WidgetToolbox.h>
 #include <ModuleBase_PageBase.h>
@@ -302,6 +303,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::
     result = new ModuleBase_WidgetExprEditor( theParent, myWidgetApi, aPlaceHolder );
   } else if (theType == WDG_MULTISELECTOR) {
     result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi);
+  } else if (theType == WDG_CONCEALED_OBJECTS_VIEW) {
+    result = new ModuleBase_WidgetConcealedObjects(theParent, myWidgetApi);
   } else if (theType == WDG_TOOLBOX) {
     result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi);
   } else if (theType == WDG_SWITCH) {