ModuleBase_WidgetLineEdit.h
ModuleBase_WidgetMultiSelector.h
ModuleBase_WidgetSelector.h
+ ModuleBase_WidgetSelectorStore.h
ModuleBase_WidgetShapeSelector.h
ModuleBase_WidgetSwitch.h
ModuleBase_WidgetToolbox.h
ModuleBase_WidgetLineEdit.cpp
ModuleBase_WidgetMultiSelector.cpp
ModuleBase_WidgetSelector.cpp
+ ModuleBase_WidgetSelectorStore.cpp
ModuleBase_WidgetShapeSelector.cpp
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetToolbox.cpp
}
}
+GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
+{
+ GeomShapePtr aShape;
+ if (!theAttribute.get())
+ return aShape;
+
+ std::string aType = theAttribute->attributeType();
+ if (aType == ModelAPI_AttributeReference::typeId()) {
+ } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (aRefAttr.get() && !aRefAttr->isObject()) {
+ AttributePtr anAttribute = aRefAttr->attr();
+ aShape = theWorkshop->module()->findShape(anAttribute);
+ }
+ } else if (aType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theAttribute);
+ aShape = aSelectAttr->value();
+ }
+ return aShape;
+}
+
} // namespace ModuleBase_Tools
const std::shared_ptr<GeomAPI_Shape>& theShape,
ModuleBase_IWorkshop* theWorkshop,
const bool theTemporarily = false);
+
+/// Returns the shape of the attribute. If the attribute is AttributeRefAttrPtr, the shape is found
+/// using current module of the given workshop.
+/// \param theAttribute an attribute where the shape is set
+/// \param theWorkshop to find a shape for the given attribute
+MODULEBASE_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop);
+
}
#endif
ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData)
-: ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
- mySelectionCount(0)
+: ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
{
QGridLayout* aMainLay = new QGridLayout(this);
ModuleBase_Tools::adjustMargins(aMainLay);
return true;
}
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::storeAttributeValue()
-{
- ModuleBase_WidgetValidated::storeAttributeValue();
-
- DataPtr aData = myFeature->data();
- AttributePtr anAttribute = aData->attribute(attributeID());
- std::string aType = anAttribute->attributeType();
- if (aType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
- mySelectionType = aSelectionListAttr->selectionType();
- mySelectionCount = aSelectionListAttr->size();
- }
- else if (aType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
- mySelectionCount = aRefListAttr->size();
- }
- else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
- mySelectionCount = aRefAttrListAttr->size();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
-{
- ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
-
- DataPtr aData = myFeature->data();
- AttributePtr anAttribute = aData->attribute(attributeID());
- std::string aType = anAttribute->attributeType();
- if (aType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
- aSelectionListAttr->setSelectionType(mySelectionType);
-
- // restore selection in the attribute. Indeed there is only one stored object
- int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
- for (int i = 0; i < aCountAppened; i++)
- aSelectionListAttr->removeLast();
- }
- else if (aType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
- // restore objects in the attribute. Indeed there is only one stored object
- int aCountAppened = aRefListAttr->size() - mySelectionCount;
- for (int i = 0; i < aCountAppened; i++)
- aRefListAttr->removeLast();
- }
- else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
- // restore objects in the attribute. Indeed there is only one stored object
- int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
- for (int i = 0; i < aCountAppened; i++)
- aRefAttrListAttr->removeLast();
- }
-}
-
//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
const bool theToValidate)
TopoDS_Shape aShape;
AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
if (anAttribute.get()) {
- GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute);
+ GeomShapePtr aGeomShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
theValues.append(ModuleBase_ViewerPrs(anObject, aGeomShape, NULL));
}
}
virtual bool restoreValueCustom();
- /// Creates a backup of the current values of the attribute
- /// It should be realized in the specific widget because of different
- /// parameters of the current attribute
- virtual void storeAttributeValue();
-
/// Set the focus on the last item in the list
virtual void updateFocus();
/// \return a list of shapes
virtual QIntList getShapeTypes() const;
- /// Creates a backup of the current values of the attribute
- /// It should be realized in the specific widget because of different
- /// parameters of the current attribute
- /// \param theValid a boolean flag, if restore happens for valid parameters
- virtual void restoreAttributeValue(const bool theValid);
-
/// Set current shape type for selection
void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
QAction* myCopyAction;
QAction* myDeleteAction;
- /// backup parameters of the model attribute. The class processes three types of attribute:
- /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
- /// values are reserved in the backup
- /// Variable of selection type
- std::string mySelectionType;
-
- /// Variable of GeomSelection
- int mySelectionCount; // number of elements in the attribute selection list when store
-
/// A flag to store use_choice parameter state
bool myIsUseChoice;
};
return activateFilters(toActivate);
}
-//********************************************************************
-void ModuleBase_WidgetSelector::setObject(ObjectPtr theObject,
- GeomShapePtr theShape)
-{
- DataPtr aData = myFeature->data();
- ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape,
- myWorkshop, myIsInValidate);
-}
-
//********************************************************************
void ModuleBase_WidgetSelector::activateCustom()
{
GeomShapePtr aShape;
getGeomSelection(thePrs, anObject, aShape);
- setObject(anObject, aShape);
+ AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
+ ModuleBase_Tools::setObject(anAttribute, anObject, aShape, myWorkshop, false);
return true;
}
// NDS: has body is temporary
virtual void updateSelectionName() {};
- /// Store the values to the model attribute of the widget. It casts this attribute to
- /// the specific type and set the given values
- /// \param theSelectedObject an object
- /// \param theShape a selected shape, which is used in the selection attribute
- /// \return true if it is succeed
- void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
/// The methiod called when widget is activated
virtual void activateCustom();
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetSelectorStore.cpp
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+#include <ModuleBase_WidgetSelectorStore.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_IWorkshop.h>
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttrList.h>
+
+ModuleBase_WidgetSelectorStore::ModuleBase_WidgetSelectorStore()
+: myIsObject(false), mySelectionType(""), mySelectionCount(0)
+{
+}
+
+void ModuleBase_WidgetSelectorStore::storeAttributeValue(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop)
+{
+ if (!theAttribute.get())
+ return;
+
+ std::string aType = theAttribute->attributeType();
+ if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ mySelectionType = aSelectionListAttr->selectionType();
+ mySelectionCount = aSelectionListAttr->size();
+ }
+ else if (aType == ModelAPI_AttributeRefList::typeId()) {
+ AttributeRefListPtr aRefListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+ mySelectionCount = aRefListAttr->size();
+ }
+ else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+ AttributeRefAttrListPtr aRefAttrListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+ mySelectionCount = aRefAttrListAttr->size();
+ }
+ else {
+ myObject = ModuleBase_Tools::getObject(theAttribute);
+ myShape = ModuleBase_Tools::getShape(theAttribute, theWorkshop);
+ myRefAttribute = AttributePtr();
+ myIsObject = false;
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (aRefAttr) {
+ myIsObject = aRefAttr->isObject();
+ myRefAttribute = aRefAttr->attr();
+ }
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelectorStore::restoreAttributeValue(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop)
+{
+ std::string aType = theAttribute->attributeType();
+ if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ aSelectionListAttr->setSelectionType(mySelectionType);
+ // restore selection in the attribute. Indeed there is only one stored object
+ int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
+ for (int i = 0; i < aCountAppened; i++)
+ aSelectionListAttr->removeLast();
+ }
+ else if (aType == ModelAPI_AttributeRefList::typeId()) {
+ AttributeRefListPtr aRefListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+ // restore objects in the attribute. Indeed there is only one stored object
+ int aCountAppened = aRefListAttr->size() - mySelectionCount;
+ for (int i = 0; i < aCountAppened; i++)
+ aRefListAttr->removeLast();
+ }
+ else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+ AttributeRefAttrListPtr aRefAttrListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+ // restore objects in the attribute. Indeed there is only one stored object
+ int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
+ for (int i = 0; i < aCountAppened; i++)
+ aRefAttrListAttr->removeLast();
+ }
+ else {
+ ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true);
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (aRefAttr) {
+ if (!myIsObject)
+ aRefAttr->setAttr(myRefAttribute);
+ }
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetSelectorStore.h
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetSelectorStore_H
+#define ModuleBase_WidgetSelectorStore_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
+#include <GeomAPI_Shape.h>
+
+class ModuleBase_IWorkshop;
+
+/**
+* \ingroup GUI
+ Provides for an attribute backup of values. It is possible to store/ restore the attribute values.
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetSelectorStore
+{
+ public:
+
+ /// Constructor
+ ModuleBase_WidgetSelectorStore();
+ /// Destructor
+ virtual ~ModuleBase_WidgetSelectorStore() {}
+
+ /// Creates a backup of the current values of the attribute
+ /// \param theAttribute a model attribute which parameters are to be stored
+ /// \param theWorkshop a current workshop
+ void storeAttributeValue(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop);
+
+ /// Creates a backup of the current values of the attribute
+ /// \param theAttribute a model attribute which parameters are to be restored
+ /// \param theWorkshop a current workshop
+ void restoreAttributeValue(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop);
+
+private:
+ /// backup parameters of the model attribute. The class processes three types of attribute:
+ /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
+ /// values are reserved in the backup
+ /// An attribute object
+ ObjectPtr myObject;
+ /// An attribute shape
+ GeomShapePtr myShape;
+ /// A reference of the attribute
+ AttributePtr myRefAttribute;
+ /// A boolean value whether refAttr uses reference of object
+ bool myIsObject;
+
+ /// Variable of selection type
+ std::string mySelectionType;
+ /// Variable of GeomSelection
+ int mySelectionCount; // number of elements in the attribute selection list when store
+
+};
+
+#endif
{
GeomShapePtr aShape;
DataPtr aData = myFeature->data();
- if (!aData->isValid())
- return aShape;
-
- std::string aType = aData->attribute(attributeID())->attributeType();
- if (aType == ModelAPI_AttributeReference::typeId()) {
- } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr.get() && !aRefAttr->isObject()) {
- AttributePtr anAttribute = aRefAttr->attr();
- aShape = myWorkshop->module()->findShape(anAttribute);
- }
- } else if (aType == ModelAPI_AttributeSelection::typeId()) {
- AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
- aShape = aSelectAttr->value();
+ if (aData->isValid()) {
+ AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
+ aShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
}
-
return aShape;
}
}
}
}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::storeAttributeValue()
-{
- ModuleBase_WidgetValidated::storeAttributeValue();
-
- DataPtr aData = myFeature->data();
- AttributePtr anAttribute = myFeature->attribute(attributeID());
-
- myObject = ModuleBase_Tools::getObject(anAttribute);
- myShape = getShape();
- myRefAttribute = AttributePtr();
- myIsObject = false;
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- myIsObject = aRefAttr->isObject();
- myRefAttribute = aRefAttr->attr();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
-{
- ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
-
- DataPtr aData = myFeature->data();
- AttributePtr anAttribute = myFeature->attribute(attributeID());
-
- setObject(myObject, myShape);
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- if (!myIsObject)
- aRefAttr->setAttr(myRefAttribute);
- }
-}
virtual bool restoreValueCustom();
- /// Creates a backup of the current values of the attribute
- /// It should be realized in the specific widget because of different
- /// parameters of the current attribute
- virtual void storeAttributeValue();
-
- /// Creates a backup of the current values of the attribute
- /// It should be realized in the specific widget because of different
- /// parameters of the current attribute
- /// \param theValid a boolean flag, if restore happens for valid parameters
- virtual void restoreAttributeValue(const bool theValid);
-
/// Computes and updates name of selected object in the widget
virtual void updateSelectionName();
/// List of accepting shapes types
QStringList myShapeTypes;
-
- /// backup parameters of the model attribute. The class processes three types of attribute:
- /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
- /// values are reserved in the backup
- /// An attribute object
- ObjectPtr myObject;
- /// An attribute shape
- GeomShapePtr myShape;
- /// A reference of the attribute
- AttributePtr myRefAttribute;
- /// A boolean value whether refAttr uses reference of object
- bool myIsObject;
};
#endif
#include <ModuleBase_FilterFactory.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_ISelection.h>
+#include <ModuleBase_WidgetSelectorStore.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData),
- myWorkshop(theWorkshop), myIsInValidate(false)
+ myWorkshop(theWorkshop)
{
+ myAttributeStore = new ModuleBase_WidgetSelectorStore();
}
ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
{
+ delete myAttributeStore;
}
//********************************************************************
void ModuleBase_WidgetValidated::storeAttributeValue()
{
myIsInValidate = true;
+ DataPtr aData = myFeature->data();
+ AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+ myAttributeStore->storeAttributeValue(anAttribute, myWorkshop);
}
//********************************************************************
void ModuleBase_WidgetValidated::restoreAttributeValue(const bool theValid)
{
myIsInValidate = false;
+
+ DataPtr aData = myFeature->data();
+ AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+ myAttributeStore->restoreAttributeValue(anAttribute, myWorkshop);
}
//********************************************************************
class QWidget;
class ModuleBase_IWorkshop;
class ModuleBase_ISelection;
+class ModuleBase_WidgetSelectorStore;
class ModelAPI_Validator;
class Config_WidgetAPI;
class Handle_SelectMgr_EntityOwner;
ObjectPtr myPresentedObject; /// back up of the filtered object
QList<ModuleBase_ViewerPrs> myValidPrs; /// cash of valid selection presentations
QList<ModuleBase_ViewerPrs> myInvalidPrs; /// cash of invalid selection presentations
+
+ /// store to backup parameters of the model
+ ModuleBase_WidgetSelectorStore* myAttributeStore;
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
/// \param theValid a boolean flag, if restore happens for valid parameters
- void restoreAttributeValue(const bool theValid);
+ virtual void restoreAttributeValue(const bool theValid);
/// Return an object and geom shape by the viewer presentation
/// \param thePrs a selection