This is especially useful for multi-selection control, which should process all possible selected presentations and give back non-used.
AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
GeomShapePtr aShape1 = aRef1->value();
+ if (!aShape1.get())
+ aShape1 = aRef1->context()->shape();
GeomShapePtr aShape2 = aRef2->value();
+ if (!aShape2.get())
+ aShape2 = aRef2->context()->shape();
if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
tooltip="Select a first point"
shape_types="vertex">
<validator id="GeomValidators_ConstructionComposite"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
</shape_selector>
<shape_selector id="SecondPoint"
label="Second point"
tooltip="Select a second point"
shape_types="vertex">
<validator id="GeomValidators_ConstructionComposite"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
<validator id="PartSet_DifferentShapes"/>
</shape_selector>
</box>
// It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
// GeomAPI_Shape. It is important to use the realization of the isEqual method from
// GeomAPI_Vertex class
- aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
+ if (aShape.get()) {
+ aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
+ }
+ else {
+ // an empty shape is used in attribute selection if the shape of the result is equal to
+ // the selected shape, so according to the upper condifition, the result is true
+ aValid = true;
+ }
}
if (!aValid) {
ResultConstructionPtr aConstr =
return isDone;
}
-void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
+void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj)
{
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
}
-void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) const
+void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj)
{
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
/// 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
- /// \param thePosition an index in the list of values, the values should be get from the index
- virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
return false;
}
/// \return Current Editing mode
bool isEditingMode() const { return myIsEditing; }
+ /// Sends Update and Redisplay for the given object
+ /// \param theObj is updating object
+ static void updateObject(ObjectPtr theObj);
+
+ /// Sends Move event for the given object
+ /// \param theObj is object for moving
+ static void moveObject(ObjectPtr theObj);
+
signals:
/// The signal about widget values are to be changed
void beforeValuesChanged();
/// The methiod called when widget is activated
virtual void activateCustom() {};
- /// Sends Update and Redisplay for the given object
- /// \param theObj is updating object
- void updateObject(ObjectPtr theObj) const;
-
- /// Sends Move event for the given object
- /// \param theObj is object for moving
- void moveObject(ObjectPtr theObj) const;
-
protected slots:
/// Processing of values changed in model widget by store the current value to the feature
void onWidgetValuesChanged();
myPropertyPanel->activateNextWidget(NULL);
return;
}
-
+
ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0;
QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
bool isSet = false;
// 1. apply the selection to controls
- int aCurrentPosition = 0;
for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
aWgt = (*aWIt);
if (!aWgt->canSetValue())
continue;
- if (!aWgt->setSelection(myPreSelection, aCurrentPosition/*aValue*/)) {
+ if (!aWgt->setSelection(myPreSelection)) {
isSet = false;
break;
} else {
aFilledWgt = aWgt;
}
}
+ // in order to redisplay object in the viewer, the update/redisplay signals should be flushed
+ // it is better to perform it not in setSelection of each widget, but do it here,
+ // after the preselection is processed
+ ModuleBase_ModelWidget::updateObject(myFeature);
+
// 2. ignore not obligatory widgets
/*for (; aWIt != aWidgets.constEnd(); ++aWIt) {
aWgt = (*aWIt);
}
//********************************************************************
-bool ModuleBase_WidgetMultiSelector::setSelection(const QList<ModuleBase_ViewerPrs>& theValues,
- int& thePosition)
+bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
- if (thePosition < 0)
- return false;
+ QList<ModuleBase_ViewerPrs> aSkippedValues;
QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
bool isDone = false;
- for (int i = thePosition; i < theValues.size(); i++) {
- ModuleBase_ViewerPrs aValue = theValues[i];
+ for (; anIt != aLast; anIt++) {
+ ModuleBase_ViewerPrs aValue = *anIt;
bool aProcessed = false;
if (isValidSelection(aValue)) {
aProcessed = setSelectionCustom(aValue);
}
+ else
+ aSkippedValues.append(aValue);
// if there is at least one set, the result is true
isDone = isDone || aProcessed;
- // when an object, which do not satisfy the validating process, stop set selection
- if (!aProcessed)
- break;
- else
- thePosition++;
}
- if (isDone) {
- updateObject(myFeature);
+ // updateObject - to update/redisplay feature
+ // it is commented in order to perfom it outside the method
+ //if (isDone) {
+ //updateObject(myFeature);
// this emit is necessary to call store/restore method an restore type of selection
- emit valuesChanged();
- }
+ //emit valuesChanged();
+ //}
+ theValues.clear();
+ if (!aSkippedValues.empty())
+ theValues.append(aSkippedValues);
+
return isDone;
}
/// 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
- /// \param thePosition an index in the list of values, the values should be get from the index
- virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
/// Checks the widget validity. By default, it returns true.
/// \param theValue a selected presentation in the view
ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId);
virtual ~ModuleBase_WidgetToolbox();
+
+ /// Defines if it is supported to set the value in this widget
+ /// It returns false because this is an info widget
+ virtual bool canSetValue() const { return false; };
+
/// Overrides ModuleBase_PagedContainer
int addPage(ModuleBase_PageBase* theWidget,
const QString& theName, const QString& theCaseId);
}
//********************************************************************
-bool ModuleBase_WidgetValidated::setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
+bool ModuleBase_WidgetValidated::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
- if (thePosition < 0 || thePosition >= theValues.size())
+ if (theValues.empty())
return false;
- ModuleBase_ViewerPrs aValue = theValues[thePosition];
- thePosition++;
-
+ // it removes the processed value from the parameters list
+ ModuleBase_ViewerPrs aValue = theValues.takeFirst();
bool isDone = false;
if (isValidSelection(aValue)) {
isDone = setSelectionCustom(aValue);
- updateObject(myFeature);
- emit valuesChanged();
+ // updateObject - to update/redisplay feature
+ // it is commented in order to perfom it outside the method
+ //updateObject(myFeature);
+ // to storeValue()
+ //emit valuesChanged();
}
return isDone;
}
/// The method is called by the current operation to process the operation preselection.
/// It is redefined to check the value validity and if it is, fill the attribute with by value
/// \param theValues the wrapped selection values
- /// \param thePosition an index in the list of values, the values should be get from the index
- virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
protected:
/// Creates a backup of the current values of the attribute
/// \param theOwner a selected owner
virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
- virtual void removePresentations() {};
-
/// Checks the current attibute in all attribute validators
// \return true if all validators return that the attribute is valid
bool isValidAttribute() const;
{
}
-bool PartSet_WidgetPoint2D::setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
+bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
- if (thePosition < 0 || thePosition >= theValues.size())
+ if (theValues.empty())
return false;
- ModuleBase_ViewerPrs aValue = theValues[thePosition];
- thePosition++;
+
+ ModuleBase_ViewerPrs aValue = theValues.takeFirst();
Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
bool isDone = false;
/// 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(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
+ /// \param theValues the wrapped widget values
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
virtual bool restoreValue();
erasePreviewPlanes();
}
-bool PartSet_WidgetSketchLabel::setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
+bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
{
// do not use the given selection if the plane of the sketch has been already set.
// If this check is absent, a selected plane in the viewer can be set in the sketch
if (plane().get())
return true;
- return ModuleBase_WidgetValidated::setSelection(theValues, thePosition);
+ return ModuleBase_WidgetValidated::setSelection(theValues);
}
QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
/// The method is called by the current operation to process the operation preselection.
/// It is redefined to do nothing if the plane of the sketch has been already set.
/// \param theValues the wrapped selection values
- /// \param thePosition an index in the list of values, the values should be get from the index
- virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
virtual bool restoreValue()
{