Interpolation_6 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_1], False, False)
model.do()
-# TODO uncomment
-#model.testNbResults(Interpolation_6, 0)
+model.testNbResults(Interpolation_6, 0)
# =============================================================================
# Test 7. Try to create curve on a single point 3
P_1 = model.selection("VERTEX", "Point_1")
P_2 = model.selection("VERTEX", "Point_2")
-# TODO uncomment
-#Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2],
-# False, False)
-#model.do()
-#model.testNbResults(Interpolation_10, 0)
+Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2],
+ False, False)
+model.do()
+model.testNbResults(Interpolation_10, 0)
# =============================================================================
# Test 11. Check subshapes naming
P_1 = model.selection("VERTEX", "Point_1")
P_2 = model.selection("VERTEX", "Point_2")
-# TODO uncomment
-#Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
-#model.do()
+Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
+model.do()
-#model.testNbResults(Polyline_9, 0)
+model.testNbResults(Polyline_9, 0)
# =============================================================================
# Test 10. Check subshapes naming
tooltip="Select points or vertices objects."
type_choice="vertices"
concealment="true">
+ <validator id="GeomValidators_DifferentShapes"/>
</multi_selector>
<boolvalue id="closed" label="Closed" tooltip="Makes the curve closed." default="false"/>
<boolvalue id="reorder" label="Reorder" tooltip="Changes the order of points to construct the shortest curve." default="false"/>
tooltip="Select points or vertices objects."
type_choice="vertices"
concealment="true">
+ <validator id="GeomValidators_DifferentShapes"/>
</multi_selector>
<boolvalue id="closed" label="Closed" tooltip="Makes the polyline closed." default="false"/>
<validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/>
GeomAPI_Wire.h
GeomAPI_Ellipse.h
GeomAPI_Ellipse2d.h
+ GeomAPI_Tools.h
)
SET(PROJECT_SOURCES
GeomAPI_Wire.cpp
GeomAPI_Ellipse.cpp
GeomAPI_Ellipse2d.cpp
+ GeomAPI_Tools.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "GeomAPI_Tools.h"
+
+#include "GeomAPI_Vertex.h"
+#include "GeomAPI_Edge.h"
+#include "GeomAPI_Face.h"
+#include "GeomAPI_Wire.h"
+
+//==================================================================================================
+GeomShapePtr GeomAPI_Tools::getTypedShape(const GeomShapePtr& theShape)
+{
+ GeomShapePtr aTypedShape = theShape;
+
+ GeomAPI_Shape::ShapeType aType = theShape->shapeType();
+
+ switch (theShape->shapeType()) {
+ case GeomAPI_Shape::VERTEX:
+ aTypedShape = GeomShapePtr(new GeomAPI_Vertex(theShape));
+ break;
+ case GeomAPI_Shape::EDGE:
+ aTypedShape = GeomShapePtr(new GeomAPI_Edge(theShape));
+ break;
+ case GeomAPI_Shape::FACE:
+ aTypedShape = GeomShapePtr(new GeomAPI_Face(theShape));
+ break;
+ case GeomAPI_Shape::WIRE:
+ aTypedShape = GeomShapePtr(new GeomAPI_Wire(theShape));
+ break;
+ }
+
+ return aTypedShape;
+}
--- /dev/null
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef GeomAPI_Tools_H_
+#define GeomAPI_Tools_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Shape.h"
+
+/// \class GeomAPI_Tools
+/// \ingroup DataModel
+/// \brief Provides auxiliary methods for shapes processing
+class GeomAPI_Tools
+{
+public:
+ /// \brief Returns typed shape.
+ /// \param[in] theShape the shape.
+ /// \return shape of the corresponding type
+ GEOMAPI_EXPORT static GeomShapePtr getTypedShape(const GeomShapePtr& theShape);
+};
+
+#endif
\ No newline at end of file
#include <Events_InfoMessage.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include "ModelAPI_Object.h"
#include <GeomAPI_Shape.h>
+#include <GeomAPI_Tools.h>
+//=================================================================================================
bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const
{
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ bool isValid = false;
+
+ std::string anAttributeType = theAttribute->attributeType();
+ bool isList = anAttributeType == ModelAPI_AttributeSelectionList::typeId();
+
+ std::list<AttributePtr> anAttrs;
+ if (isList) {
+ AttributeSelectionListPtr aListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ // get all selection attributes from the list
+ for (int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+ anAttrs.push_back(aListAttr->value(anIndex));
+ }
+
+ isValid = checkEquals(anAttrs);
+ }
+ else {
+ // get all feature selection attributes
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
+
+ isValid = checkEqualToCurrent(anAttrs, theAttribute);
+ }
+
+ if (!isValid) {
+ theError = isList ? "The selection list contains equal shapes." :
+ "The feature uses equal shapes.";
+ return false;
+ }
+
+ return true;
+}
+
+//=================================================================================================
+bool GeomValidators_DifferentShapes::checkEquals(std::list<AttributePtr>& theAttributes)
+{
+ std::list<AttributePtr>::iterator anIt = theAttributes.begin();
+ for (; anIt != theAttributes.end(); anIt++) {
+ AttributePtr anAttribute = *anIt;
+
+ std::list<AttributePtr>::iterator anOthersIt = std::next(anIt);
+ for (; anOthersIt != theAttributes.end(); anOthersIt++) {
+ AttributePtr anOtherAttribute = *anOthersIt;
+ if (isAttrShapesEqual(anAttribute, anOtherAttribute)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+//=================================================================================================
+bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list<AttributePtr>& theAttributes,
+ const AttributePtr& theCurrentAttribute)
+{
AttributeSelectionPtr aSelectionAttribute =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theCurrentAttribute);
+
GeomShapePtr aShape = aSelectionAttribute->value();
if (!aShape.get()) {
ResultPtr aResult = aSelectionAttribute->context();
aShape = aResult->shape();
}
- std::string aCurrentAttributeId = theAttribute->id();
- // get all feature attributes
- std::list<AttributePtr> anAttrs =
- aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
- if (anAttrs.size() > 0 && aShape.get() != NULL) {
- std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
- for(; anAttr != anAttrs.end(); anAttr++) {
+ std::string aCurrentAttributeId = theCurrentAttribute->id();
+ if (theAttributes.size() > 0 && aShape.get() != NULL) {
+ std::list<AttributePtr>::iterator anAttr = theAttributes.begin();
+ for (; anAttr != theAttributes.end(); anAttr++) {
AttributePtr anAttribute = *anAttr;
// take into concideration only other attributes
if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
anAttrShape = aResult->shape();
}
if (aShape->isEqual(anAttrShape)) {
- theError = "The feature uses equal shapes.";
return false;
}
}
}
}
}
+
return true;
}
+
+bool GeomValidators_DifferentShapes::isAttrShapesEqual(const AttributePtr& theAttribute,
+ const AttributePtr& theOtherAttribute)
+{
+ AttributeSelectionPtr aSelectionAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ AttributeSelectionPtr anOtherSelectionAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theOtherAttribute);
+
+ GeomShapePtr aShape = aSelectionAttribute->value();
+ if (!aShape.get()) {
+ ResultPtr aResult = aSelectionAttribute->context();
+ if (aResult.get())
+ aShape = aResult->shape();
+ }
+ GeomShapePtr aTypedShape = GeomAPI_Tools::getTypedShape(aShape);
+
+ GeomShapePtr anOtherShape = anOtherSelectionAttribute->value();
+ if (!anOtherShape.get()) {
+ ResultPtr aResult = anOtherSelectionAttribute->context();
+ if (aResult.get())
+ anOtherShape = aResult->shape();
+ }
+ GeomShapePtr aOtherTypedShape = GeomAPI_Tools::getTypedShape(anOtherShape);
+
+ return aTypedShape->isEqual(aOtherTypedShape);
+}
\ No newline at end of file
GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const;
+
+private:
+ /// Check if the list contains equal shape selection.
+ static bool checkEquals(std::list<AttributePtr>& theAttributes);
+ /// Check if the list contains shape selection equal to the given one.
+ static bool checkEqualToCurrent(std::list<AttributePtr>& theAttributes,
+ const AttributePtr& theCurrentAttribute);
+ /// Check if shapes corresponding to the attributes are equal.
+ static bool isAttrShapesEqual(const AttributePtr& theAttribute,
+ const AttributePtr& theOtherAttribute);
};
#endif