The reason is preselection: to set an empty shape to the feature attribute if the selected shape is equal to the shape of result, check of selection valid state
ModuleBase_WidgetDoubleValue.h
ModuleBase_WidgetEditor.h
ModuleBase_WidgetFactory.h
- ModuleBase_WidgetShapeSelector.h
ModuleBase_IWorkshop.h
ModuleBase_Definitions.h
ModuleBase_SelectionValidator.h
ModuleBase_PageWidget.h
ModuleBase_PageGroupBox.h
ModuleBase_PagedContainer.h
+ ModuleBase_WidgetSelector.h
+ ModuleBase_WidgetShapeSelector.h
ModuleBase_WidgetSwitch.h
ModuleBase_WidgetToolbox.h
ModuleBase_WidgetValidated.h
ModuleBase_WidgetDoubleValue.cpp
ModuleBase_WidgetEditor.cpp
ModuleBase_WidgetFactory.cpp
- ModuleBase_WidgetShapeSelector.cpp
ModuleBase_WidgetChoice.cpp
ModuleBase_WidgetFileSelector.cpp
ModuleBase_DoubleSpinBox.cpp
ModuleBase_PageWidget.cpp
ModuleBase_PageGroupBox.cpp
ModuleBase_PagedContainer.cpp
+ ModuleBase_WidgetSelector.cpp
+ ModuleBase_WidgetShapeSelector.cpp
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetToolbox.cpp
ModuleBase_WidgetValidated.cpp
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_WidgetValidated(theParent, theData, theParentId),
- myWorkshop(theWorkshop)
+ : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId)
{
QGridLayout* aMainLay = new QGridLayout(this);
ModuleBase_Tools::adjustMargins(aMainLay);
myTypeCombo = new QComboBox(this);
// There is no sence to paramerize list of types while we can not parametrize selection mode
- myShapeValidator = new GeomValidators_ShapeType();
-
std::string aPropertyTypes = theData->getProperty("type_choice");
QString aTypesStr = aPropertyTypes.c_str();
QStringList aShapeTypes = aTypesStr.split(' ');
ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
{
- delete myShapeValidator;
-}
-
-//TODO: nds stabilization hotfix
-void ModuleBase_WidgetMultiSelector::disconnectSignals()
-{
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-}
-
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::activateCustom()
-{
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
- connect(myWorkshop, SIGNAL(selectionChanged()),
- this, SLOT(onSelectionChanged()),
- Qt::UniqueConnection);
-
- activateShapeSelection(true);
-
- // Restore selection in the viewer by the attribute selection list
- myWorkshop->setSelected(getAttributeSelection());
-
- activateFilters(myWorkshop, true);
-}
-
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::deactivate()
-{
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- activateShapeSelection(false);
- activateFilters(myWorkshop, false);
}
//********************************************************************
}
}
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::clearAttribute()
+{
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+ aSelectionListAttr->clear();
+}
+
//********************************************************************
void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
GeomShapePtr theShape)
//********************************************************************
void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
{
+ clearAttribute();
+
+ // Store shape type
DataPtr aData = myFeature->data();
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- if (aSelectionListAttr.get() == NULL)
- return;
- aSelectionListAttr->clear();
-
- // Store shapes type
aSelectionListAttr->setSelectionType(mySelectionType);
// Store selection in the attribute
}
}
-//********************************************************************
-bool ModuleBase_WidgetMultiSelector::acceptSubShape(const TopoDS_Shape& theShape) const
-{
- bool aValid = true;
- if (theShape.IsNull()) {
- aValid = true; // do not check the shape type if the shape is empty
- // extrusion uses a sketch object selectected in Object browser
- }
- else {
- aValid = false;
- TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
- if (myTypeCombo->count() > 1) {
- TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText());
- aValid = aShapeType == aType;
- }
- else {
- for(int i = 0, aCount = myTypeCombo->count(); i < aCount && !aValid; i++) {
- TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
- aValid = aShapeType == aType;
- }
- }
- }
- return aValid;
-}
-
//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
//********************************************************************
bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
-#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
- return true;
-#endif
- GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
- // if there is no result(the feature is presentable only), result is false
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
- bool aValid = aResult.get() != NULL;
+ bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
if (aValid) {
- // if there is no selected shape, the method returns true
- if (!aShape.get())
- aValid = true;
- else {
- // Check that the selection corresponds to selection type
- TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
- aValid = acceptSubShape(aTopoShape);
- }
- }
-
- if (aValid) {
- if (myFeature) {
- // We can not select a result of our feature
- const std::list<ResultPtr>& aResList = myFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- bool isSkipSelf = false;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aResult) {
- isSkipSelf = true;
- break;
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ aValid = aResult.get() != NULL;
+ if (aValid) {
+ if (myFeature) {
+ // We can not select a result of our feature
+ const std::list<ResultPtr>& aResList = myFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ bool isSkipSelf = false;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ if ((*aIt) == aResult) {
+ isSkipSelf = true;
+ break;
+ }
}
+ if (isSkipSelf)
+ aValid = false;
}
- if(isSkipSelf)
- aValid = false;
}
}
-
return aValid;
}
-//********************************************************************
-bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
- // DEBUG_THE_SAME_AS_SHAPE
- ObjectPtr anObject;
- GeomShapePtr aShape;
- getGeomSelection(thePrs, anObject, aShape);
-
- setObject(anObject, aShape);
- return true;
-}
-
//********************************************************************
QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
{
//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
{
- activateShapeSelection(true);
+ activateSelection(true);
activateFilters(myWorkshop, true);
QList<ModuleBase_ViewerPrs> anEmptyList;
// This method will call Selection changed event which will call onSelectionChanged
myWorkshop->setSelected(anEmptyList);
}
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::onSelectionChanged()
+void ModuleBase_WidgetMultiSelector::updateFocus()
{
- QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls);
-
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- aSelectionListAttr->clear();
-
- setSelection(aSelected);
-
- emit valuesChanged();
- // the updateObject method should be called to flush the updated sigal. The workshop listens it,
- // calls validators for the feature and, as a result, updates the Apply button state.
- updateObject(myFeature);
-
// Set focus to List control in order to make possible
// to use Tab key for transfer the focus to next widgets
myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
myListControl->setFocus();
}
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::updateSelectionName()
+{
+}
+
+//********************************************************************
+QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
+{
+ QIntList aShapeTypes;
+
+ if (myTypeCombo->count() > 1) {
+ aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
+ }
+ else {
+ for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
+ aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)));
+ }
+ }
+ return aShapeTypes;
+}
+
//********************************************************************
void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
{
aShapeTypeName = myTypeCombo->itemText(idx);
TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
- activateShapeSelection(false);
+ activateSelection(false);
activateFilters(myWorkshop, false);
bool isBlocked = myTypeCombo->blockSignals(true);
myTypeCombo->setCurrentIndex(idx);
myTypeCombo->blockSignals(isBlocked);
- activateShapeSelection(true);
+ activateSelection(true);
activateFilters(myWorkshop, true);
break;
}
}
}
-void ModuleBase_WidgetMultiSelector::activateShapeSelection(const bool isActivated)
-{
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
-
- if (isActivated) {
- QString aNewType = myTypeCombo->currentText();
- QIntList aList;
- if (true /*myIsUseChoice*/) {
- aList.append(ModuleBase_Tools::shapeType(aNewType));
- }
- else {
- for(int i = 0, aCount = myTypeCombo->count(); i < aCount; i++)
- aList.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)));
- }
- myWorkshop->activateSubShapesSelection(aList);
- } else {
- myWorkshop->deactivateSubShapesSelection();
- }
-}
-
QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
{
QList<ModuleBase_ViewerPrs> aSelected;
return aSelected;
}
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
- ObjectPtr& theObject,
- GeomShapePtr& theShape)
-{
- // DEBUG_THE_SAME_AS_SHAPE
- theObject = myWorkshop->selection()->getResult(thePrs);
- theShape = myWorkshop->selection()->getShape(thePrs);
-}
-
//********************************************************************
void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList)
{
QList<QListWidgetItem*> aItems = myListControl->selectedItems();
myCopyAction->setEnabled(!aItems.isEmpty());
}
-
#define MODULEBASE_WIDGETMULTISELECTOR_H_
#include <ModuleBase.h>
-#include <ModuleBase_WidgetValidated.h>
+#include <ModuleBase_WidgetSelector.h>
#include <GeomAPI_Shape.h>
#include <ModelAPI_Result.h>
* - tooltip - a tooltip for the widget
* - type_choice - list of expected shape types.
*/
-class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetValidated
+class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector
{
Q_OBJECT
public:
const std::string& theParentId);
virtual ~ModuleBase_WidgetMultiSelector();
- //TODO: nds stabilization hotfix
- virtual void disconnectSignals();
-
virtual bool restoreValue();
/// Returns list of widget controls
/// \return a control list
virtual QList<QWidget*> getControls() const;
- /// The methiod called when widget is deactivated
- virtual void deactivate();
-
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValues the wrapped selection values
/// \return a boolean value
virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
- /// Fills the attribute with the value of the selected owner
- /// \param theOwner a selected owner
- virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
public slots:
/// Slot is called on selection type changed
void onSelectionTypeChanged();
- /// Slot is called on selection changed
- virtual void onSelectionChanged();
-
protected slots:
/// Slot for copy command in a list pop-up menu
void onCopyItem();
void onListSelection();
protected:
- /// The methiod called when widget is activated
- virtual void activateCustom();
-
/// Saves the internal parameters to the given feature
/// \return True in success
virtual bool storeValueCustom() const;
/// parameters of the current attribute
virtual void storeAttributeValue();
+ /// Clear attribute
+ virtual void clearAttribute();
+
+ // Set the focus on the last item in the list
+ virtual void updateFocus();
+
+ /// Computes and updates name of selected object in the widget
+ virtual void updateSelectionName();
+
+ /// Retunrs a list of possible shape types
+ /// \return a list of shapes
+ virtual QIntList getShapeTypes() const;
+
/// Append 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 theValid a boolean flag, if restore happens for valid parameters
virtual void restoreAttributeValue(const bool theValid);
- /// Returns true if selected shape corresponds to requested shape types
- /// \param theShape a shape
- bool acceptSubShape(const TopoDS_Shape& theShape) const;
-
/// Set current shape type for selection
void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
- /// Start shape selection
- /// \param isActivated a state whether the shape is activated or deactivated in selection
- void activateShapeSelection(const bool isActivated);
-
/// Return the attribute values wrapped in a list of viewer presentations
/// \return a list of viewer presentations, which contains an attribute result and
/// a shape. If the attribute do not uses the shape, it is empty
- QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
+ virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
/// Update selection list
void updateSelectionList(AttributeSelectionListPtr);
- /// Return an object and geom shape by the viewer presentation
- /// \param thePrs a selection
- /// \param theObject an output object
- /// \param theShape a shape of the selection
- virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
- ObjectPtr& theObject,
- GeomShapePtr& theShape);
-
/// Converts the XML defined type choice to the validator type
/// For example, the "Edges" is converted to "edge"
std::string validatorType(const QString& theType) const;
- /// List control
+protected:
+ /// List control
QListWidget* myListControl;
/// Combobox of types
QComboBox* myTypeCombo;
- //TODO: Move into the base of selectors
- ModuleBase_IWorkshop* myWorkshop;
-
/// Provides correspondance between Result object and its shape
typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
/// Variable of GeomSelection
QList<GeomSelection> mySelection;
- /// An instance of the "type_choice" validator. It is returns on validating in customValidator()
- GeomValidators_ShapeType* myShapeValidator;
-
//bool myIsUseChoice;
};
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetSelector.h
+// Created: 19 June 2015
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetSelector.h>
+
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+
+ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_WidgetValidated(theParent, theData, theParentId),
+ myWorkshop(theWorkshop)
+{
+}
+
+//********************************************************************
+ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
+{
+}
+
+//TODO: nds stabilization hotfix
+void ModuleBase_WidgetSelector::disconnectSignals()
+{
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape)
+{
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ theObject = aSelection->getResult(thePrs);
+ theShape = aSelection->getShape(thePrs);
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::onSelectionChanged()
+{
+ clearAttribute();
+
+ QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
+ ModuleBase_ISelection::AllControls);
+ setSelection(aSelected);
+
+ emit valuesChanged();
+ // the updateObject method should be called to flush the updated sigal. The workshop listens it,
+ // calls validators for the feature and, as a result, updates the Apply button state.
+ updateObject(myFeature);
+
+ updateFocus();
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::acceptSubShape(const TopoDS_Shape& theShape) const
+{
+ bool aValid = true;
+ if (theShape.IsNull()) {
+ aValid = true; // do not check the shape type if the shape is empty
+ // extrusion uses a sketch object selectected in Object browser
+ }
+ else {
+ aValid = false;
+ TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
+ QIntList aShapeTypes = getShapeTypes();
+
+ QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
+ for (; anIt != aLast; anIt++) {
+ if (aShapeType == *anIt)
+ aValid = true;
+ }
+ }
+ return aValid;
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
+{
+ updateSelectionName();
+
+ if (toActivate) {
+ myWorkshop->activateSubShapesSelection(getShapeTypes());
+ } else {
+ myWorkshop->deactivateSubShapesSelection();
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::activateCustom()
+{
+ connect(myWorkshop, SIGNAL(selectionChanged()), this,
+ SLOT(onSelectionChanged()), Qt::UniqueConnection);
+
+ activateSelection(true);
+
+ // Restore selection in the viewer by the attribute selection list
+ myWorkshop->setSelected(getAttributeSelection());
+
+ activateFilters(myWorkshop, true);
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+ GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
+ bool aValid;
+ // if there is no selected shape, the method returns true
+ if (!aShape.get())
+ aValid = true;
+ else {
+ // Check that the selection corresponds to selection type
+ TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+ aValid = acceptSubShape(aTopoShape);
+ }
+ if (aValid) {
+ // In order to avoid selection of the same object
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
+ aValid = aSelectedFeature != myFeature;
+ }
+ return aValid;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+ ObjectPtr anObject;
+ GeomShapePtr aShape;
+ getGeomSelection(thePrs, anObject, aShape);
+
+ setObject(anObject, aShape);
+ return true;
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::deactivate()
+{
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ activateSelection(false);
+ activateFilters(myWorkshop, false);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetSelector.h
+// Created: 19 June 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetSelector_H
+#define ModuleBase_WidgetSelector_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_WidgetValidated.h"
+#include <ModuleBase_ViewerPrs.h>
+#include "ModuleBase_Definitions.h"
+
+#include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
+
+class Config_WidgetAPI;
+class QWidget;
+class ModuleBase_IWorkshop;
+
+/**
+* \ingroup GUI
+* Implementation of widget for selection.
+* This abstract interface is designed to be used for shape/multi shape selector widgets.
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated
+{
+Q_OBJECT
+ public:
+
+ /// Constructor
+ /// \param theParent the parent object
+ /// \param theWorkshop instance of workshop interface
+ /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ /// \param theParentId is Id of a parent of the current attribute
+ ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData, const std::string& theParentId);
+
+ virtual ~ModuleBase_WidgetSelector();
+
+ /// Defines if it is supposed that the widget should interact with the viewer.
+ virtual bool isViewerSelector() { return true; }
+
+ /// Checks the widget validity. By default, it returns true.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
+ /// Fills the attribute with the value of the selected owner
+ /// \param theOwner a selected owner
+ virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
+ /// The methiod called when widget is deactivated
+ virtual void deactivate();
+
+ //TODO: nds stabilization hotfix
+ virtual void disconnectSignals();
+
+protected:
+ /// Activate or deactivate selection
+ void activateSelection(bool toActivate);
+
+ private slots:
+ /// Slot which is called on selection event
+ void onSelectionChanged();
+
+ protected:
+ /// Set an empty value to attribute
+ virtual void clearAttribute() = 0;
+
+ // Update focus after the attribute value change
+ virtual void updateFocus() = 0;
+
+ /// Return the attribute values wrapped in a list of viewer presentations
+ /// \return a list of viewer presentations, which contains an attribute result and
+ /// a shape. If the attribute do not uses the shape, it is empty
+ virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const = 0;
+
+ /// Retunrs a list of possible shape types
+ /// \return a list of shapes
+ virtual QIntList getShapeTypes() const = 0;
+
+ /// Computes and updates name of selected object in the widget
+ virtual void updateSelectionName() = 0;
+
+ /// 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
+ virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0;
+
+ /// The methiod called when widget is activated
+ virtual void activateCustom();
+
+ /// Returns true if selected shape corresponds to requested shape types
+ /// \param theShape a shape
+ bool acceptSubShape(const TopoDS_Shape& theShape) const;
+
+ /// Return an object and geom shape by the viewer presentation
+ /// \param thePrs a selection
+ /// \param theObject an output object
+ /// \param theShape a shape of the selection
+ virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
+ ObjectPtr& theObject,
+ GeomShapePtr& theShape);
+
+ //----------- Class members -------------
+protected:
+ /// Reference to workshop
+ ModuleBase_IWorkshop* myWorkshop;
+};
+
+#endif
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_WidgetValidated(theParent, theData, theParentId),
- myWorkshop(theWorkshop)
+ : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId)
{
QFormLayout* aLayout = new QFormLayout(this);
ModuleBase_Tools::adjustMargins(aLayout);
std::string aTypes = theData->getProperty("shape_types");
myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
-
- myShapeValidator = new GeomValidators_ShapeType();
}
//********************************************************************
ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
{
- delete myShapeValidator;
}
//********************************************************************
return aSelected;
}
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
- ObjectPtr& theObject,
- GeomShapePtr& theShape)
-{
- theObject = myWorkshop->selection()->getResult(thePrs);
- theShape = myWorkshop->selection()->getShape(thePrs);
-}
-
//********************************************************************
void ModuleBase_WidgetShapeSelector::clearAttribute()
{
- DataPtr aData = myFeature->data();
- AttributeSelectionPtr aSelect = aData->selection(attributeID());
- if (aSelect) {
- aSelect->setValue(ResultPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
- return;
- }
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- aRefAttr->setObject(ObjectPtr());
- return;
- }
- AttributeReferencePtr aRef = aData->reference(attributeID());
- if (aRef) {
- aRef->setObject(ObjectPtr());
- }
+ // In order to make reselection possible, set empty object and shape should be done
+ setObject(ObjectPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
}
//********************************************************************
return aControls;
}
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::onSelectionChanged()
+void ModuleBase_WidgetShapeSelector::updateFocus()
{
- // In order to make reselection possible, set empty object and shape should be done
- setObject(ObjectPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
-
- QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls);
- bool aHasObject = setSelection(aSelected);
-
- // the updateObject method should be called to flush the updated sigal. The workshop listens it,
- // calls validators for the feature and, as a result, updates the Apply button state.
- updateObject(myFeature);
- // the widget loses the focus only if the selected object is set
- if (aHasObject)
+ ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
+ if (anObject.get())
emit focusOutWidget(this);
}
//********************************************************************
-bool ModuleBase_WidgetShapeSelector::acceptSubShape(const TopoDS_Shape& theShape) const
+QIntList ModuleBase_WidgetShapeSelector::getShapeTypes() const
{
- foreach (QString aType, myShapeTypes) {
- if (theShape.ShapeType() == ModuleBase_Tools::shapeType(aType))
- return true;
+ QIntList aShapeTypes;
+ foreach(QString aType, myShapeTypes) {
+ aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
}
- return false;
+ return aShapeTypes;
}
//********************************************************************
}
}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
-{
- updateSelectionName();
-
- if (toActivate) {
- QIntList aList;
- foreach (QString aType, myShapeTypes) {
- aList.append(ModuleBase_Tools::shapeType(aType));
- }
- myWorkshop->activateSubShapesSelection(aList);
- } else {
- myWorkshop->deactivateSubShapesSelection();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::raisePanel() const
-{
- QWidget* aParent = this->parentWidget();
- QWidget* aLastPanel = 0;
- while (!aParent->inherits("QDockWidget")) {
- aLastPanel = aParent;
- aParent = aParent->parentWidget();
- if (!aParent)
- return;
- }
- if (aParent->inherits("QDockWidget")) {
- QDockWidget* aTabWgt = (QDockWidget*) aParent;
- aTabWgt->raise();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::activateCustom()
-{
- connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- activateSelection(true);
-
- // Restore selection in the viewer by the attribute selection list
- myWorkshop->setSelected(getAttributeSelection());
-
- activateFilters(myWorkshop, true);
-}
-
//********************************************************************
void ModuleBase_WidgetShapeSelector::storeAttributeValue()
{
aRefAttr->setAttr(myRefAttribute);
}
}
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
- GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
- bool aValid;
- // if there is no selected shape, the method returns true
- if (!aShape.get())
- aValid = true;
- else {
- // Check that the selection corresponds to selection type
- TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
- aValid = acceptSubShape(aTopoShape);
- }
- if (aValid) {
- // In order to avoid selection of the same object
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
- FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
- aValid = aSelectedFeature != myFeature;
- }
- return aValid;
-}
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
- ObjectPtr anObject;
- GeomShapePtr aShape;
- getGeomSelection(thePrs, anObject, aShape);
-
- setObject(anObject, aShape);
- return true;
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::deactivate()
-{
- activateSelection(false);
- activateFilters(myWorkshop, false);
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-}
#define ModuleBase_WidgetShapeSelector_H
#include "ModuleBase.h"
-#include "ModuleBase_WidgetValidated.h"
+#include "ModuleBase_WidgetSelector.h"
#include "ModuleBase_ViewerFilters.h"
#include <ModuleBase_ViewerPrs.h>
* which corresponds to ModelAPI_ResultConstruction object type
* - concealment - hide or not hide selected object after operation
*/
-class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
+class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
{
Q_OBJECT
public:
/// \param theData the widget configuation. The attribute of the model widget is obtained from
/// \param theParentId is Id of a parent of the current attribute
ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData, const std::string& theParentId);
+ const Config_WidgetAPI* theData, const std::string& theParentId);
virtual ~ModuleBase_WidgetShapeSelector();
virtual bool restoreValue();
- /// Defines if it is supposed that the widget should interact with the viewer.
- virtual bool isViewerSelector() { return true; }
-
/// Returns list of widget controls
/// \return a control list
virtual QList<QWidget*> getControls() const;
- /// Checks the widget validity. By default, it returns true.
- /// \param theValue a selected presentation in the view
- /// \return a boolean value
- virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
- /// Fills the attribute with the value of the selected owner
- /// \param theOwner a selected owner
- virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-
- /// The methiod called when widget is deactivated
- virtual void deactivate();
-
-protected:
- /// Activate or deactivate selection
- void activateSelection(bool toActivate);
-
- private slots:
- /// Slot which is called on selection event
- void onSelectionChanged();
-
protected:
/// Saves the internal parameters to the given feature
/// \return True in success
virtual bool storeValueCustom() const;
- /// The methiod called when widget is activated
- virtual void activateCustom();
-
/// 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 restoreAttributeValue(const bool theValid);
/// Computes and updates name of selected object in the widget
- void updateSelectionName();
+ virtual void updateSelectionName();
- /// Raise panel which contains this widget
- void raisePanel() const;
+ /// Clear attribute
+ virtual void clearAttribute();
- /// Returns true if selected shape corresponds to requested shape types
- /// \param theShape a shape
- bool acceptSubShape(const TopoDS_Shape& theShape) const;
+ // Update focus after the attribute value change
+ virtual void updateFocus();
- /// Clear attribute
- void clearAttribute();
+ /// Retunrs a list of possible shape types
+ /// \return a list of shapes
+ virtual QIntList getShapeTypes() const;
/// Store the values to the model attribute of the widget. It casts this attribute to
/// the specific type and set the given values
/// Return the attribute values wrapped in a list of viewer presentations
/// \return a list of viewer presentations, which contains an attribute result and
/// a shape. If the attribute do not uses the shape, it is empty
- QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
-
- /// Return an object and geom shape by the viewer presentation
- /// \param thePrs a selection
- /// \param theObject an output object
- /// \param theShape a shape of the selection
- virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
- ObjectPtr& theObject,
- GeomShapePtr& theShape);
+ virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
//----------- Class members -------------
protected:
/// Input control of the widget
QLineEdit* myTextLine;
- /// Reference to workshop
- ModuleBase_IWorkshop* myWorkshop;
-
/// List of accepting shapes types
QStringList myShapeTypes;
AttributePtr myRefAttribute;
/// A boolean value whether refAttr uses reference of object
bool myIsObject;
-
- /// An instance of the "shape_type" validator. It is returns on validating in customValidator()
- GeomValidators_ShapeType* myShapeValidator;
};
#endif
delete myExternalObjectMgr;
}
-//********************************************************************
-void PartSet_WidgetMultiSelector::onSelectionChanged()
+bool PartSet_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
- ModuleBase_WidgetMultiSelector::onSelectionChanged();
- // TODO(nds): unite with externalObject(), remove parameters
- //myFeature->execute();
-
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
- QObjectPtrList aListOfAttributeObjects;
- for (int i = 0; i < aSelectionListAttr->size(); i++) {
- AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
- aListOfAttributeObjects.append(anAttr->context());
+ bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues);
+ if (aSucceed) {
+ // TODO(nds): unite with externalObject(), remove parameters
+ //myFeature->execute();
+
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ QObjectPtrList aListOfAttributeObjects;
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
+ aListOfAttributeObjects.append(anAttr->context());
+ }
+ myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
}
-
- myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature);
+ return aSucceed;
}
//********************************************************************
{
myIsInVaildate = true;
ModuleBase_WidgetMultiSelector::storeAttributeValue();
-
}
//********************************************************************
/// \param theData the widget configuation. The attribute of the model widget is obtained from
/// \param theParentId is Id of a parent of the current attribute
PartSet_WidgetMultiSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData, const std::string& theParentId);
+ const Config_WidgetAPI* theData, const std::string& theParentId);
virtual ~PartSet_WidgetMultiSelector();
/// Retrurns installed sketcher
CompositeFeaturePtr sketch() const { return mySketch; }
-public slots:
- /// Slot is called on selection changed
- virtual void onSelectionChanged();
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// \param theValues the wrapped selection values
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
protected:
/// Checks the widget validity. By default, it returns true.