The reason is: preselection for translation sketch operation by rectangle. The vertex shapes should not be used in the multi selector control.
TODO: to use the same mechanizm for the shape selector control.
<export_file_selector id="export_file_selector" type="save" title="Export file" path="">
<validator id="ExchangePlugin_ExportFormat" parameters="BREP:BREP,STEP|STP:STEP,IGES:IGES-5.1,IGES:IGES-5.3" />
</export_file_selector>
- <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids" />
+ <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="vertex edge face solid" />
</feature>
</group>
</workbench>
label="Main object"
icon=":icons/cut_shape.png"
tooltip="Select an object solid"
- type_choice="Solids"
+ type_choice="solid"
concealment="true"
/>
<multi_selector id="tool_objects"
label="Tool object"
icon=":icons/cut_tool.png"
tooltip="Select a tool solid"
- type_choice="Solids"
+ type_choice="solid"
concealment="true" >
<validator id="PartSet_DifferentObjects"/>
</multi_selector>-->
label="Select a sketch face"
icon=":icons/sketch.png"
tooltip="Select a sketch face"
- type_choice="Faces">
+ type_choice="face">
<validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
</multi_selector>
<groupbox title="From">
label="Select a sketch face"
icon=":icons/sketch.png"
tooltip="Select a sketch face"
- type_choice="Faces">
+ type_choice="face">
<validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
</multi_selector>
<shape_selector id="axis_object"
<source>
<multi_selector id="group_list"
tooltip="Select a set of objects"
- type_choice="Vertices Edges Faces Solids" />
+ type_choice="vertex edge face solid" />
</source>
\ No newline at end of file
return aShape.ShapeType() == TopAbs_FACE;
}
+bool GeomAPI_Shape::isSolid() const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ return aShape.ShapeType() == TopAbs_SOLID;
+}
+
bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
double& theXmax, double& theYmax, double& theZmax) const
{
/// Returns whether the shape is a face
virtual bool isFace() const;
+ /// Returns whether the shape is a solid
+ virtual bool isSolid() const;
+
/// Computes boundary dimensions of the shape
/// Returns False if it is not possible
bool computeSize(double& theXmin, double& theYmin, double& theZmin,
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Result.h>
-#include "ModelAPI_AttributeRefAttr.h"
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeReference.h>
#include <Events_Error.h>
{
if (MyEdgeTypes.size() == 0) {
MyEdgeTypes["vertex"] = Vertex;
+ MyEdgeTypes["edge"] = Edge;
MyEdgeTypes["line"] = Line;
MyEdgeTypes["circle"] = Circle;
+ MyEdgeTypes["solid"] = Solid;
+ MyEdgeTypes["face"] = Face;
}
std::string aType = std::string(theType.c_str());
if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
return MyEdgeTypes[aType];
- Events_Error::send("Edge type defined in XML is not implemented!");
+ Events_Error::send("Shape type defined in XML is not implemented!");
return AnyShape;
}
if (aShapeType == AnyShape)
return true;
- ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
- if (anObject.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShape = aResult->shape();
- if (aShape.get() != NULL) {
- switch (aShapeType) {
- case Line:
- aValid = aShape->isEdge() && !GeomAPI_Curve(aShape).isCircle();
- break;
- case Circle:
- aValid = aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
- break;
- case Vertex:
- aValid = aShape->isVertex();
- break;
- default: break;
- }
- }
+ AttributeSelectionListPtr aListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (aListAttr.get()) {
+ for (int i = 0; i < aListAttr->size(); i++) {
+ aValid = isValidAttribute(aListAttr->value(i), aShapeType);
+ if (!aValid) // if at least one attribute is invalid, the result is false
+ break;
}
}
else {
+ aValid = isValidAttribute(theAttribute, aShapeType);
+ }
+ return aValid;
+}
+
+bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute,
+ const TypeOfShape theShapeType) const
+{
+ bool aValid = false;
+
+ std::string anAttributeType = theAttribute->attributeType();
+
+ if (anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ GeomShapePtr aShape = anAttr->value();
+ if (aShape.get())
+ aValid = isValidShape(aShape, theShapeType);
+ else
+ aValid = isValidObject(anAttr->context(), theShapeType);
+ }
+ else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
if (anAttr.get() != NULL) {
- if (aShapeType == Vertex) {
+ if (anAttr->isObject()) {
+ aValid = isValidObject(anAttr->object(), theShapeType);
+ }
+ else if (theShapeType == Vertex) {
AttributePtr aRefAttr = anAttr->attr();
aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId();
}
}
}
+ else if (anAttributeType == ModelAPI_AttributeReference::typeId()) {
+ AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ if (anAttr.get() != NULL)
+ aValid = isValidObject(anAttr->value(), theShapeType);
+ }
+ return aValid;
+}
+
+bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject,
+ const TypeOfShape theShapeType) const
+{
+ bool aValid = false;
+ if (theObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShape = aResult->shape();
+ aValid = isValidShape(aShape, theShapeType);
+ }
+ }
+ return aValid;
+}
+
+bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
+ const TypeOfShape theShapeType) const
+{
+ bool aValid = false;
+
+ if (theShape.get() != NULL) {
+ switch (theShapeType) {
+ case Edge:
+ aValid = theShape->isEdge();
+ break;
+ case Line:
+ aValid = theShape->isEdge() && !GeomAPI_Curve(theShape).isCircle();
+ break;
+ case Circle:
+ aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle();
+ break;
+ case Vertex:
+ aValid = theShape->isVertex();
+ break;
+ case Solid:
+ aValid = theShape->isSolid();
+ break;
+ case Face:
+ aValid = theShape->isFace();
+ break;
+ default: break;
+ }
+ }
return aValid;
}
#include "GeomValidators.h"
#include "ModelAPI_AttributeValidator.h"
+#include <GeomAPI_Shape.h>
+
#include <string>
/**
{
AnyShape,
Vertex,
+ Edge,
Line,
- Circle
+ Circle,
+ Solid,
+ Face
};
public:
bool isValidArgument(const AttributePtr& theAttribute,
const std::string& theArgument) const;
+ /// Returns true if the attibute's object type satisfies the argument value
+ /// \param theAttribute a checked attribute
+ /// \param theArgument a parameter
+ bool isValidAttribute(const AttributePtr& theAttribute,
+ const TypeOfShape theShapeType) const;
+
+ /// Returns true if the attibute's object type satisfies the argument value
+ /// \param theAttribute a checked object
+ /// \param theShapeType a shape type
+ bool isValidObject(const ObjectPtr& theObject,
+ const TypeOfShape theShapeType) const;
+
+ /// Returns true if the attibute's object type satisfies the argument value
+ /// \param theShape a checked shape
+ /// \param theShapeType a shape type
+ bool isValidShape(const GeomShapePtr theShape,
+ const TypeOfShape theShapeType) const;
+
};
#endif
#include <ModuleBase_Tools.h>
#include <ModuleBase_Definitions.h>
+#include <GeomValidators_ShapeType.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
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(' ');
{
activateShapeSelection(false);
activateFilters(myWorkshop, false);
+
+ delete myShapeValidator;
}
//********************************************************************
}
}
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::customValidators(
+ std::list<ModelAPI_Validator*>& theValidators,
+ std::list<std::list<std::string> >& theArguments) const
+{
+ std::list<std::string> anArguments;
+
+ theValidators.push_back(myShapeValidator);
+ QString aType = myTypeCombo->currentText();
+ anArguments.push_back(aType.toStdString().c_str());
+ theArguments.push_back(anArguments);
+}
+
//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelection(const QList<ModuleBase_ViewerPrs>& theValues,
int& thePosition)
#include <QString>
#include <QStringList>
#include <QPair>
+#include <QMap>
class QWidget;
class QListWidget;
class QComboBox;
class ModuleBase_IWorkshop;
+class GeomValidators_ShapeType;
class QAction;
* \code
* <multi_selector id="group_list"
* tooltip="Select a set of objects"
-* type_choice="Vertices Edges Faces Solids" />
+* type_choice="vertex edge face solid" />
* \endcode
* It uses folloing parameters:
* - id - is a name of corresponded attribute
/// \param theValid a boolean flag, if restore happens for valid parameters
virtual void restoreAttributeValue(const bool theValid);
+ /// Puts additional validators to the given list. A separate validator is created for each of the
+ /// "type_choice" value
+ /// \param theValidators a list of validators
+ /// \param theArguments a list of validators arguments
+ virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
+ std::list<std::list<std::string> >& theArguments) const;
+
/// Set current shape type for selection
void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
/// Variable of GeomSelection
QList<GeomSelection> mySelection;
+
+ /// A map of "type_choice" validators.
+ GeomValidators_ShapeType* myShapeValidator;
};
#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
std::list<std::list<std::string> > anArguments;
aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments);
+ customValidators(aValidators, anArguments);
+
DataPtr aData = myFeature->data();
AttributePtr anAttribute = myFeature->attribute(attributeID());
aViewer->removeSelectionFilter(aSelFilter);
}
+void ModuleBase_WidgetValidated::customValidators(std::list<ModelAPI_Validator*>& theValidators,
+ std::list<std::list<std::string> >& theArguments) const
+{
+}
+
QList<ModuleBase_ViewerPrs> ModuleBase_WidgetValidated::getSelectedEntitiesOrObjects(
ModuleBase_ISelection* theSelection) const
{
class QWidget;
class ModuleBase_IWorkshop;
class ModuleBase_ISelection;
+class ModelAPI_Validator;
class Config_WidgetAPI;
class Handle_SelectMgr_EntityOwner;
/// \param toActivate a flag about activation or deactivation the filters
virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
+ /// Puts additional validators to the given list
+ /// \param theValidators a list of validators
+ /// \param theArguments a list of validators arguments
+ virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
+ std::list<std::list<std::string> >& theArguments) const;
+
/// Returns a list of selected presentations. Firstly it is obtained from the viewer,
/// if there are not selected objects in the viewer, it get the selection from the object browser.
/// If the browser has selected objects, the viewer prs objects are created with only object
<sketch_multi_selector id="ConstraintMirrorList"
label="List of objects"
tooltip="Select list of mirroring objects"
- type_choice="Edges"
+ type_choice="edge"
use_external="true">
<validator id="SketchPlugin_MirrorAttr" />
</sketch_multi_selector>
<sketch_multi_selector id="MultiTranslationList"
label="List of objects"
tooltip="Select list of translating objects"
- type_choice="Edges"
+ type_choice="edge"
use_external="true">
<validator id="SketchPlugin_CopyValidator" />
</sketch_multi_selector>
<sketch_multi_selector id="MultiRotationList"
label="List of objects"
tooltip="Select list of rotating objects"
- type_choice="Edges"
+ type_choice="edge"
use_external="true">
<validator id="SketchPlugin_CopyValidator" />
</sketch_multi_selector>