//********************************************************************
bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
{
- bool isStored = storeAttributeValues(mySelectedObject, myShape);
- if (isStored)
- updateObject(myFeature);
- return isStored;
+ // the value is stored on the selection changed signal processing
+ return true;
}
//********************************************************************
//********************************************************************
bool ModuleBase_WidgetShapeSelector::restoreValue()
{
- DataPtr aData = myFeature->data();
bool isBlocked = this->blockSignals(true);
-
- AttributeSelectionPtr aSelect = aData->selection(attributeID());
- if (aSelect) {
- mySelectedObject = aSelect->context();
- myShape = aSelect->value();
- } else {
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- mySelectedObject = aRefAttr->object();
- } else {
- AttributeReferencePtr aRef = aData->reference(attributeID());
- if (aRef) {
- mySelectedObject = aRef->value();
- }
- }
- }
updateSelectionName();
-
this->blockSignals(isBlocked);
+
return true;
}
bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
{
ObjectPtr aObject = theValue.object();
- if ((!mySelectedObject) && (!aObject))
+ ObjectPtr aCurrentObject = getObject();
+ if ((!aCurrentObject) && (!aObject))
return false;
// Check that the selected object is result (others can not be accepted)
//********************************************************************
void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
{
- mySelectedObject = theObj;
- myShape = theShape;
- if (mySelectedObject) {
+ if (storeAttributeValues(theObj, theShape))
+ updateObject(myFeature);
+
+ if (theObj) {
raisePanel();
}
updateSelectionName();
return false;
}
+//********************************************************************
+ObjectPtr ModuleBase_WidgetShapeSelector::getObject() const
+{
+ ObjectPtr anObject;
+
+ DataPtr aData = myFeature->data();
+ if (aData.get() == NULL)
+ return anObject;
+
+ AttributeSelectionPtr aSelect = aData->selection(attributeID());
+ if (aSelect) {
+ anObject = aSelect->context();
+ } else {
+ AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+ if (aRefAttr) {
+ anObject = aRefAttr->object();
+ } else {
+ AttributeReferencePtr aRef = aData->reference(attributeID());
+ if (aRef) {
+ anObject = aRef->value();
+ }
+ }
+ }
+ return anObject;
+}
+
+//********************************************************************
+GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
+{
+ GeomShapePtr aShape;
+ DataPtr aData = myFeature->data();
+ if (aData.get() == NULL)
+ return aShape;
+
+ AttributeSelectionPtr aSelect = aData->selection(attributeID());
+ if (aSelect)
+ aShape = aSelect->value();
+
+ return aShape;
+}
+
//********************************************************************
void ModuleBase_WidgetShapeSelector::updateSelectionName()
{
}
}
if (!isNameUpdated) {
- if (mySelectedObject) {
- std::string aName = mySelectedObject->data()->name();
+ ObjectPtr anObject = getObject();
+ if (anObject.get() != NULL) {
+ std::string aName = anObject->data()->name();
myTextLine->setText(QString::fromStdString(aName));
} else {
if (myIsActive) {
// 2. store the current values, disable the model's update
aData->blockSendAttributeUpdated(true);
- ObjectPtr aPrevSelectedObject = mySelectedObject;
- GeomShapePtr aPrevShape = myShape;
-
storeAttributeValues(theObj, theShape);
// 3. check the acceptability of the current values
/// \return a control list
virtual QList<QWidget*> getControls() const;
- /// Returns currently selected data object
- ObjectPtr selectedFeature() const
- {
- return mySelectedObject;
- }
-
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValue the wrapped widget value
virtual bool setSelection(ModuleBase_ViewerPrs theValue);
-
/// The methiod called when widget is deactivated
virtual void deactivate();
+ // Get the object from the attribute
+ /// \param theObj an object
+ static ObjectPtr getObject(const AttributePtr& theAttribute) const;
public slots:
/// \param theShape a shape
void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
+ // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
+ /// \return a shape
+ GeomShapePtr getShape() const;
+
/// Check the selected with validators if installed
/// \param theObj the object for checking
/// \param theShape the shape for checking
/// Reference to workshop
ModuleBase_IWorkshop* myWorkshop;
- /// Pointer to selected object
- ObjectPtr mySelectedObject;
-
- /// Pointer to selected shape
- GeomShapePtr myShape;
-
/// List of accepting shapes types
QStringList myShapeTypes;