From: nds Date: Fri, 29 Jul 2016 19:02:51 +0000 (+0300) Subject: Recover feature X-Git-Tag: V_2.5.0~153 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=95b5b61c8b3e0ab0de64955952894cd32bc49e06;p=modules%2Fshaper.git Recover feature --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 43227a571..adb9ae00c 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -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"; diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 763e5138c..5b5ab88fe 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -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 diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 54b0021f0..0daaa1ec1 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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 index 000000000..5eb5aa84e --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -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 +#include +#include +#include +#include +#include + +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 index 000000000..e24db88c1 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.h @@ -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 +#include + +/**\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 diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 6a5cba33d..98786b67b 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -56,6 +56,14 @@ + + + + + diff --git a/src/FeaturesPlugin/recover_widget.xml b/src/FeaturesPlugin/recover_widget.xml new file mode 100644 index 000000000..daf0d16b5 --- /dev/null +++ b/src/FeaturesPlugin/recover_widget.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 8dd3b5de7..74a793206 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -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 index 000000000..ba83b7734 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetConcealedObjects.cpp @@ -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 +#include + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +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(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 > > > aRefs; + myBaseFeature->data()->referencesToObjects(aRefs); + std::list > >::const_iterator + anIt = aRefs.begin(), aLast = aRefs.end(); + for (; anIt != aLast; anIt++) { + std::list anObjects = (*anIt).second; + std::list::const_iterator anOIt = anObjects.begin(), anOLast = anObjects.end(); + for (; anOIt != anOLast; anOIt++) { + ResultPtr aResult = std::dynamic_pointer_cast(*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(myView->cellWidget(i, 0)); + bool isChecked = anAttributeList->isInList(aResult); + + bool aBlocked = aButton->blockSignals(true); + aButton->setChecked(isChecked); + aButton->blockSignals(aBlocked); + } + return true; +} + +QList ModuleBase_WidgetConcealedObjects::getControls() const +{ + QList result; + result << myView; + return result; +} + +void ModuleBase_WidgetConcealedObjects::addViewRow(const std::shared_ptr& 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 index 000000000..b289d7a87 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetConcealedObjects.h @@ -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 +#include + +#include +#include +#include + +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 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& 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 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 > myConcealedResults; +}; + +#endif /* MODULEBASE_WIDGETCONCEALEDOBJECTS_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index a33522dee..8af4cbb32 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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) {