%include "GeomAPI_XYZ.h"
%include "GeomAPI_Trsf.h"
%include "GeomAPI_Wire.h"
+
+%include "std_list.i"
+%include "std_set.i"
+
+%template(PointList) std::list<std::shared_ptr<GeomAPI_Pnt> >;
+%template(PointSet) std::set<std::shared_ptr<GeomAPI_Pnt> >;
%module GeomAlgoAPI
%{
#include "GeomAlgoAPI_swig.h"
+
+ // fix for SWIG v2.0.4
+ #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj))
%}
// import other modules
%{
#include "ModelAPI_swig.h"
+
+ // fix for SWIG v2.0.4
+ #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj))
%}
// import other modules
// std::list -> []
%template(StringList) std::list<std::string>;
%template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
+%template(FeatureList) std::list<std::shared_ptr<ModelAPI_Feature> >;
%template(ResultList) std::list<std::shared_ptr<ModelAPI_Result> >;
%template(DocumentList) std::list<std::shared_ptr<ModelAPI_Document> >;
// std::set -> []
// shared pointers
// For Point2D.method()
-%shared_ptr(ModelAPI_Point2D)
+%shared_ptr(ModelGeomAlgo_Point2D)
// all supported interfaces
%include "ModelGeomAlgo_Point2D.h"
#pragma warning(disable : 4996) // for sprintf
#endif
-namespace ModelGeomAlgo_Point2D {
- std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(ModelAPI_Feature* theFeature,
+std::shared_ptr<GeomDataAPI_Point2D> ModelGeomAlgo_Point2D::getPointOfRefAttr(
+ ModelAPI_Feature* theFeature,
const std::string& theAttribute,
const std::string& theObjectFeatureKind,
const std::string& theObjectFeatureAttribute)
- {
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
-
- /// essential check as it is called in openGl thread
- if (!theFeature || !theFeature->data().get() || !theFeature->data()->isValid())
- return std::shared_ptr<GeomDataAPI_Point2D>();
-
- FeaturePtr aFeature;
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
- if(anAttr.get() && anAttr->isInitialized()) {
- aFeature = ModelAPI_Feature::feature(anAttr->object());
- if (aFeature.get()) {
- bool aFeatureOfObjectKind = !theObjectFeatureKind.empty() &&
- !theObjectFeatureAttribute.empty() &&
- aFeature->getKind() == theObjectFeatureKind;
- if(aFeatureOfObjectKind)
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->data()->attribute(theObjectFeatureAttribute));
- else if (anAttr->attr())
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
- }
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+ /// essential check as it is called in openGl thread
+ if (!theFeature || !theFeature->data().get() || !theFeature->data()->isValid())
+ return std::shared_ptr<GeomDataAPI_Point2D>();
+
+ FeaturePtr aFeature;
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
+ if(anAttr.get() && anAttr->isInitialized()) {
+ aFeature = ModelAPI_Feature::feature(anAttr->object());
+ if (aFeature.get()) {
+ bool aFeatureOfObjectKind = !theObjectFeatureKind.empty() &&
+ !theObjectFeatureAttribute.empty() &&
+ aFeature->getKind() == theObjectFeatureKind;
+ if(aFeatureOfObjectKind)
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(theObjectFeatureAttribute));
+ else if (anAttr->attr())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
}
- return aPointAttr;
}
+ return aPointAttr;
+}
- void getPointsOfReference(const std::shared_ptr<ModelAPI_Object>& theObject,
+void ModelGeomAlgo_Point2D::getPointsOfReference(
+ const std::shared_ptr<ModelAPI_Object>& theObject,
const std::string& theReferenceFeatureKind,
std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::string& theObjectFeatureKind,
const std::string& theObjectFeatureAttribute,
const bool isSkipFeatureAttributes)
- {
- // find by feature
- FeaturePtr aSourceFeature = ModelAPI_Feature::feature(theObject);
-
- const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
- std::set<AttributePtr>::const_iterator aIt;
- for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- if (aRefFeature->getKind() == theReferenceFeatureKind) {
- std::list<AttributePtr> anAttributes =
- aRefFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
- std::list<AttributePtr>::iterator anIter = anAttributes.begin(), aLast = anAttributes.end();
- bool isSkippedAttribute = false;
- if (isSkipFeatureAttributes) {
- for(anIter = anAttributes.begin(); anIter != aLast && !isSkippedAttribute; anIter++) {
- AttributeRefAttrPtr aRefAttribute =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
- if (aRefAttribute.get() && !aRefAttribute->isObject()) {
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttribute->attr());
- FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aPointAttr->owner());
- isSkippedAttribute = aSourceFeature == anAttributeFeature;
- }
- }
- }
- if (isSkippedAttribute)
- continue;
+{
+ // find by feature
+ FeaturePtr aSourceFeature = ModelAPI_Feature::feature(theObject);
- // it searches the first point of AttributeRefAtt
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
- for(anIter = anAttributes.begin(); anIter != aLast && !aPointAttr.get(); anIter++) {
+ const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aRefFeature->getKind() == theReferenceFeatureKind) {
+ std::list<AttributePtr> anAttributes =
+ aRefFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+ std::list<AttributePtr>::iterator anIter = anAttributes.begin(), aLast = anAttributes.end();
+ bool isSkippedAttribute = false;
+ if (isSkipFeatureAttributes) {
+ for(anIter = anAttributes.begin(); anIter != aLast && !isSkippedAttribute; anIter++) {
AttributeRefAttrPtr aRefAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
- if (aRefAttribute.get()) {
- aPointAttr = getPointOfRefAttr(aRefFeature.get(), aRefAttribute->id(),
- theObjectFeatureKind, theObjectFeatureAttribute);
+ if (aRefAttribute.get() && !aRefAttribute->isObject()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttribute->attr());
+ FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aPointAttr->owner());
+ isSkippedAttribute = aSourceFeature == anAttributeFeature;
}
}
- if (aPointAttr.get()) {
- theAttributes.insert(aPointAttr);
+ }
+ if (isSkippedAttribute)
+ continue;
+
+ // it searches the first point of AttributeRefAtt
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+ for(anIter = anAttributes.begin(); anIter != aLast && !aPointAttr.get(); anIter++) {
+ AttributeRefAttrPtr aRefAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
+ if (aRefAttribute.get()) {
+ aPointAttr = getPointOfRefAttr(aRefFeature.get(), aRefAttribute->id(),
+ theObjectFeatureKind, theObjectFeatureAttribute);
}
}
- }
- // find by results
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
- if (aFeature.get()) {
- const std::list<std::shared_ptr<ModelAPI_Result> > aResults = aFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- for (; aRIter != aResults.cend(); aRIter++) {
- ResultPtr aResult = *aRIter;
- getPointsOfReference(aResult, theReferenceFeatureKind, theAttributes, theObjectFeatureKind,
- theObjectFeatureAttribute);
+ if (aPointAttr.get()) {
+ theAttributes.insert(aPointAttr);
}
}
}
+ // find by results
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature.get()) {
+ const std::list<std::shared_ptr<ModelAPI_Result> > aResults = aFeature->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for (; aRIter != aResults.cend(); aRIter++) {
+ ResultPtr aResult = *aRIter;
+ getPointsOfReference(aResult, theReferenceFeatureKind, theAttributes, theObjectFeatureKind,
+ theObjectFeatureAttribute);
+ }
+ }
+}
- void appendPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
+void appendPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
const std::shared_ptr<ModelAPI_Result>& theResult,
- PointToRefsMap& thePointToAttributeOrObject)
- {
+ ModelGeomAlgo_Point2D::PointToRefsMap& thePointToAttributeOrObject)
+{
+ bool aPointFound = false;
+ FeaturePtr aPointFeature = ModelAPI_Feature::feature(theResult);
+ // check if the given point is already in the container in attribute list
+ for (ModelGeomAlgo_Point2D::PointToRefsMap::const_iterator
+ anIt = thePointToAttributeOrObject.begin();
+ anIt != thePointToAttributeOrObject.end() && !aPointFound; anIt++) {
+ std::shared_ptr<GeomAPI_Pnt> aPoint = anIt->first;
+ if (aPoint->isEqual(thePoint)) {
+ std::list<std::shared_ptr<GeomDataAPI_Point2D> > anAttributes = anIt->second.first;
+ for (std::list<AttributePoint2DPtr>::const_iterator anAttrIt = anAttributes.begin();
+ anAttrIt != anAttributes.end() && !aPointFound; anAttrIt++) {
+ AttributePtr anAttribute = *anAttrIt;
+ aPointFound = ModelAPI_Feature::feature(anAttribute->owner()) == aPointFeature;
+ }
+ }
+ }
+
+ if (!aPointFound) {
if (thePointToAttributeOrObject.find(thePoint) != thePointToAttributeOrObject.end())
thePointToAttributeOrObject.at(thePoint).second.push_back(theResult);
else {
thePointToAttributeOrObject[thePoint] = std::make_pair(anAttributes, anObjects);
}
}
+}
- void appendShapePoints(const GeomShapePtr& theShape,
- const std::shared_ptr<ModelAPI_Result>& theResult,
- PointToRefsMap& thePointToAttributeOrObject)
- {
- if (!theShape.get())
- return;
+void appendShapePoints(const GeomShapePtr& theShape,
+ const std::shared_ptr<ModelAPI_Result>& theResult,
+ ModelGeomAlgo_Point2D::PointToRefsMap& thePointToAttributeOrObject)
+{
+ if (!theShape.get())
+ return;
- switch (theShape->shapeType()) {
- case GeomAPI_Shape::VERTEX: {
- std::shared_ptr<GeomAPI_Vertex> aVertex =
- std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(theShape));
- std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
- appendPoint(aPnt, theResult, thePointToAttributeOrObject);
- }
- break;
- case GeomAPI_Shape::EDGE: {
- std::shared_ptr<GeomAPI_Edge> anEdge =
- std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(theShape));
- appendPoint(anEdge->firstPoint(), theResult, thePointToAttributeOrObject);
- appendPoint(anEdge->lastPoint(), theResult, thePointToAttributeOrObject);
- }
- break;
- case GeomAPI_Shape::COMPOUND: {
- for(GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
- appendShapePoints(anIt.current(), theResult, thePointToAttributeOrObject);
- }
+ switch (theShape->shapeType()) {
+ case GeomAPI_Shape::VERTEX: {
+ std::shared_ptr<GeomAPI_Vertex> aVertex =
+ std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(theShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ appendPoint(aPnt, theResult, thePointToAttributeOrObject);
+ }
+ break;
+ case GeomAPI_Shape::EDGE: {
+ std::shared_ptr<GeomAPI_Edge> anEdge =
+ std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(theShape));
+ appendPoint(anEdge->firstPoint(), theResult, thePointToAttributeOrObject);
+ appendPoint(anEdge->lastPoint(), theResult, thePointToAttributeOrObject);
+ }
+ break;
+ case GeomAPI_Shape::COMPOUND: {
+ for(GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
+ appendShapePoints(anIt.current(), theResult, thePointToAttributeOrObject);
}
- break;
- default: break;
}
+ break;
+ default: break;
}
+}
- void getPointsIntersectedShape(const std::shared_ptr<ModelAPI_Feature>& theBaseFeature,
+void ModelGeomAlgo_Point2D::getPointsIntersectedShape(const std::shared_ptr<ModelAPI_Feature>& theBaseFeature,
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
PointToRefsMap& thePointToAttributeOrObject)
+{
+ GeomShapePtr aFeatureShape;
{
- GeomShapePtr aFeatureShape;
- {
+ std::set<ResultPtr> anEdgeShapes;
+ ModelGeomAlgo_Shape::shapesOfType(theBaseFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
+ if (anEdgeShapes.empty())
+ return;
+ aFeatureShape = (*anEdgeShapes.begin())->shape();
+ }
+
+ std::list<std::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = theFeatures.begin(),
+ aLast = theFeatures.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = *anIt;
+ if (aFeature.get() == theBaseFeature.get())
+ continue;
+ if (aFeature.get()) {
std::set<ResultPtr> anEdgeShapes;
- ModelGeomAlgo_Shape::shapesOfType(theBaseFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
+ ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
if (anEdgeShapes.empty())
- return;
- aFeatureShape = (*anEdgeShapes.begin())->shape();
- }
+ ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::VERTEX, anEdgeShapes);
- std::list<std::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = theFeatures.begin(),
- aLast = theFeatures.end();
- for (; anIt != aLast; anIt++) {
- FeaturePtr aFeature = *anIt;
- if (aFeature.get() == theBaseFeature.get())
+ if (anEdgeShapes.empty())
continue;
- if (aFeature.get()) {
- std::set<ResultPtr> anEdgeShapes;
- ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
- if (anEdgeShapes.empty())
- continue;
- ResultPtr aResult = *anEdgeShapes.begin();
- GeomShapePtr aShape = aResult->shape();
-
- GeomShapePtr aShapeOfIntersection = aFeatureShape->intersect(aShape);
- appendShapePoints(aShapeOfIntersection, aResult, thePointToAttributeOrObject);
- }
+ ResultPtr aResult = *anEdgeShapes.begin();
+ GeomShapePtr aShape = aResult->shape();
+
+ GeomShapePtr aShapeOfIntersection = aFeatureShape->intersect(aShape);
+ appendShapePoints(aShapeOfIntersection, aResult, thePointToAttributeOrObject);
}
}
+}
+
+std::list<std::shared_ptr<GeomAPI_Pnt> > ModelGeomAlgo_Point2D::getSetOfPntIntersectedShape(
+ const std::shared_ptr<ModelAPI_Feature>& theBaseFeature,
+ const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures)
+{
+ std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+
+ PointToRefsMap aRefsMap;
+ getPointsIntersectedShape(theBaseFeature, theFeatures, aRefsMap);
+
+ for (PointToRefsMap::const_iterator aPointIt = aRefsMap.begin();
+ aPointIt != aRefsMap.end(); aPointIt++)
+ aPoints.push_back(aPointIt->first);
+
+ return aPoints;
+}
- void getPointsInsideShape(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+void ModelGeomAlgo_Point2D::getPointsInsideShape(
+ const std::shared_ptr<GeomAPI_Shape> theBaseShape,
const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
const std::shared_ptr<GeomAPI_Dir>& theDirX,
const std::shared_ptr<GeomAPI_Dir>& theDirY,
PointToRefsMap& thePointToAttributeOrObject)
- {
- std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator anIt = theAttributes.begin(),
- aLast = theAttributes.end();
- for (; anIt != aLast; anIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> anAttribute = *anIt;
- std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
- std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
- std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
- if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
- if (thePointToAttributeOrObject.find(aProjectedPoint) != thePointToAttributeOrObject.end())
- thePointToAttributeOrObject.at(aProjectedPoint).first.push_back(anAttribute);
- else {
- std::list<std::shared_ptr<GeomDataAPI_Point2D> > anAttributes;
- std::list<std::shared_ptr<ModelAPI_Object> > anObjects;
- anAttributes.push_back(anAttribute);
- thePointToAttributeOrObject[aProjectedPoint] = std::make_pair(anAttributes, anObjects);
- }
+{
+ std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator anIt = theAttributes.begin(),
+ aLast = theAttributes.end();
+ for (; anIt != aLast; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttribute = *anIt;
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
+ std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
+ std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
+ if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
+ if (thePointToAttributeOrObject.find(aProjectedPoint) != thePointToAttributeOrObject.end())
+ thePointToAttributeOrObject.at(aProjectedPoint).first.push_back(anAttribute);
+ else {
+ std::list<std::shared_ptr<GeomDataAPI_Point2D> > anAttributes;
+ std::list<std::shared_ptr<ModelAPI_Object> > anObjects;
+ anAttributes.push_back(anAttribute);
+ thePointToAttributeOrObject[aProjectedPoint] = std::make_pair(anAttributes, anObjects);
}
}
}
+}
- void getPointsInsideShape_p(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+void ModelGeomAlgo_Point2D::getPointsInsideShape_p(
+ const std::shared_ptr<GeomAPI_Shape> theBaseShape,
const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
const std::shared_ptr<GeomAPI_Dir>& theDirX,
std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
std::map<std::shared_ptr<GeomDataAPI_Point2D>,
std::shared_ptr<GeomAPI_Pnt> >& theAttributeToPoint)
- {
- std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator anIt = theAttributes.begin(),
- aLast = theAttributes.end();
- for (; anIt != aLast; anIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> anAttribute = *anIt;
- std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
- std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
- std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
- if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
- thePoints.push_back(aProjectedPoint);
- theAttributeToPoint[anAttribute] = aProjectedPoint;
- }
+{
+ std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator anIt = theAttributes.begin(),
+ aLast = theAttributes.end();
+ for (; anIt != aLast; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttribute = *anIt;
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
+ std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
+ std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
+ if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
+ thePoints.push_back(aProjectedPoint);
+ theAttributeToPoint[anAttribute] = aProjectedPoint;
}
}
+}
- bool isPointOnEdge(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+bool ModelGeomAlgo_Point2D::isPointOnEdge(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
const std::shared_ptr<GeomAPI_Pnt>& thePoint,
std::shared_ptr<GeomAPI_Pnt>& theProjectedPoint)
- {
- bool isInside = false;
- if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
- if (anEdge->isLine()) {
- std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
- theProjectedPoint = aLine->project(thePoint);
- }
- else if (anEdge->isCircle() || anEdge->isArc()) {
- std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
- theProjectedPoint = aCircle->project(thePoint);
- }
- if (theProjectedPoint.get()) {
- std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
- theProjectedPoint->y(), theProjectedPoint->z()));
- isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
- }
+{
+ bool isInside = false;
+ if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
+ if (anEdge->isLine()) {
+ std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+ theProjectedPoint = aLine->project(thePoint);
+ }
+ else if (anEdge->isCircle() || anEdge->isArc()) {
+ std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
+ theProjectedPoint = aCircle->project(thePoint);
+ }
+ if (theProjectedPoint.get()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
+ theProjectedPoint->y(), theProjectedPoint->z()));
+ isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
}
- return isInside;
}
+ return isInside;
+}
- std::string doubleToString(double theValue)
- {
- std::string aValueStr;
- char aBuf[50];
- int n = sprintf(aBuf, "%g", theValue);
- aValueStr = std::string(aBuf);
- return aValueStr;
- }
+std::string doubleToString(double theValue)
+{
+ std::string aValueStr;
+ char aBuf[50];
+ int n = sprintf(aBuf, "%g", theValue);
+ aValueStr = std::string(aBuf);
+ return aValueStr;
+}
#ifdef _DEBUG
- std::string getPontAttributesInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::set<std::shared_ptr<ModelAPI_Attribute> >& theAttributesOnly)
- {
- std::string anInfo;
-
- std::list<AttributePtr> anAttrs = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
- std::list<AttributePtr>::const_iterator anIt = anAttrs.begin(), aLast = anAttrs.end();
-
- for(; anIt != aLast; anIt++) {
- AttributePtr anAttribute = *anIt;
- if (anAttribute.get() && (theAttributesOnly.empty() ||
- theAttributesOnly.find(anAttribute) != theAttributesOnly.end())) {
- if (!anInfo.empty()) {
- anInfo.append(", ");
- anInfo.append("\n");
- }
- anInfo.append(" " + getPointAttributeInfo(anAttribute));
- }
+std::string ModelGeomAlgo_Point2D::getPontAttributesInfo(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::set<std::shared_ptr<ModelAPI_Attribute> >& theAttributesOnly)
+{
+ std::string anInfo;
+
+ std::list<AttributePtr> anAttrs = theFeature->data()->attributes(
+ GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::const_iterator anIt = anAttrs.begin(), aLast = anAttrs.end();
+
+ for(; anIt != aLast; anIt++) {
+ AttributePtr anAttribute = *anIt;
+ if (anAttribute.get() && (theAttributesOnly.empty() ||
+ theAttributesOnly.find(anAttribute) != theAttributesOnly.end())) {
+ if (!anInfo.empty()) {
+ anInfo.append(", ");
+ anInfo.append("\n");
+ }
+ anInfo.append(" " + getPointAttributeInfo(anAttribute));
}
- return anInfo;
}
+ return anInfo;
+}
- std::string getPointAttributeInfo(const std::shared_ptr<ModelAPI_Attribute>& theAttribute)
- {
- std::string anInfo;
- std::string aValue = "not defined";
- std::string aType = theAttribute->attributeType();
- if (aType == GeomDataAPI_Point2D::typeId()) {
- std::shared_ptr<GeomDataAPI_Point2D> aPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
- if (aPoint.get() && aPoint->isInitialized()) {
- aValue = std::string("(" + doubleToString(aPoint->x()) + ", "+
- doubleToString(aPoint->y()) + ")");
- }
+std::string ModelGeomAlgo_Point2D::getPointAttributeInfo(
+ const std::shared_ptr<ModelAPI_Attribute>& theAttribute)
+{
+ std::string anInfo;
+ std::string aValue = "not defined";
+ std::string aType = theAttribute->attributeType();
+ if (aType == GeomDataAPI_Point2D::typeId()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
+ if (aPoint.get() && aPoint->isInitialized()) {
+ aValue = std::string("(" + doubleToString(aPoint->x()) + ", "+
+ doubleToString(aPoint->y()) + ")");
}
- anInfo.append(theAttribute->id() + ": " + aValue);
-
- return anInfo;
}
+ anInfo.append(theAttribute->id() + ": " + aValue);
+
+ return anInfo;
+}
#endif
-} // namespace ModelGeomAlgo_Point2D
#include <map>
-namespace ModelGeomAlgo_Point2D {
-
+class ModelGeomAlgo_Point2D
+{
+public:
/// Searches Point2D attribute of reference of the attribute of given feature
/// \param theFeature a feature to obtain AttributeRefAttr
/// \param theAttribute a name of AttributeRefAttr on the given feature
/// \param theObjectFeatureAttribute a feature attribute in object that satisfies the search
/// \param isSkipFeatureAttributes a boolean value if coincidences to the feature attributes
/// \returns found point attribute or NULL
- MODELGEOMALGO_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(
+ static MODELGEOMALGO_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(
ModelAPI_Feature* theFeature,
const std::string& theAttribute,
const std::string& theObjectFeatureKind = "",
/// \param isSkipFeatureAttributes a boolean value if coincidences to the feature attributes
/// should be skipped
/// \returns found point attribute or NULL
- MODELGEOMALGO_EXPORT void getPointsOfReference(const std::shared_ptr<ModelAPI_Object>& theObject,
+ static MODELGEOMALGO_EXPORT void getPointsOfReference(const std::shared_ptr<ModelAPI_Object>& theObject,
const std::string& theReferenceFeatureKind,
std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::string& theObjectFeatureKind = "",
std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
- MODELGEOMALGO_EXPORT void getPointsIntersectedShape(
+ static MODELGEOMALGO_EXPORT void getPointsIntersectedShape(
const std::shared_ptr<ModelAPI_Feature>& theBaseFeature,
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
PointToRefsMap& thePointToAttributeOrObject);
+ static MODELGEOMALGO_EXPORT std::list<std::shared_ptr<GeomAPI_Pnt> > getSetOfPntIntersectedShape(
+ const std::shared_ptr<ModelAPI_Feature>& theBaseFeature,
+ const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures);
+
/// Removes attributes which points are out of the base shape
/// \param theBaseShape a shape of check
/// \param theAttributes a container of point 2D attributes
/// \param theDirY plane X direction to generate 3D point by 2D attribute point
/// \param thePoints a container of 3D points belong to the shape
/// \param theAttributeToPoint a container of attribute to point
- MODELGEOMALGO_EXPORT void getPointsInsideShape(
+ static MODELGEOMALGO_EXPORT void getPointsInsideShape(
const std::shared_ptr<GeomAPI_Shape> theBaseShape,
const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
/// \param theDirY plane X direction to generate 3D point by 2D attribute point
/// \param thePoints a container of 3D points belong to the shape
/// \param theAttributeToPoint a container of attribute to point
- MODELGEOMALGO_EXPORT void getPointsInsideShape_p(
+ static MODELGEOMALGO_EXPORT void getPointsInsideShape_p(
const std::shared_ptr<GeomAPI_Shape> theBaseShape,
const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
std::map<std::shared_ptr<GeomDataAPI_Point2D>,
std::shared_ptr<GeomAPI_Pnt> >& theAttributeToPoint);
-
/// Finds projected point to the given shape line
/// \param theBaseShape a shape of check
/// \param thePoint [in] a point to project
/// \param theProjectedPoint [out] a projected point
- MODELGEOMALGO_EXPORT bool isPointOnEdge(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+ static MODELGEOMALGO_EXPORT bool isPointOnEdge(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
const std::shared_ptr<GeomAPI_Pnt>& thePoint,
std::shared_ptr<GeomAPI_Pnt>& theProjectedPoint);
+
#ifdef _DEBUG
/// Return feature name, kind and point values united in a string info
/// \param theFeature an investigated feature
/// \param theAttributesOnly a container of necessary attributes, if empty, all
/// \return string value
- MODELGEOMALGO_EXPORT std::string getPontAttributesInfo(
- const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::set<std::shared_ptr<ModelAPI_Attribute> >& theAttributesOnly);
+ static MODELGEOMALGO_EXPORT std::string getPontAttributesInfo(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::set<std::shared_ptr<ModelAPI_Attribute> >& theAttributesOnly);
/// Return point attribute string info
/// \param theAttribute an investigated attribute
/// \return string value
- MODELGEOMALGO_EXPORT std::string getPointAttributeInfo(
- const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
+ static MODELGEOMALGO_EXPORT std::string getPointAttributeInfo(
+ const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
#endif
-}
+};
#endif
}
//********************************************************************
-bool ModuleBase_WidgetValidated::isValidAttribute(const AttributePtr& theAttribute) const
+bool ModuleBase_WidgetValidated::isValidAttribute(const AttributePtr& theAttribute)
{
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
bool& isFlushesActived,
bool& isAttributeSetInitializedBlocked,
bool& isAttributeSendUpdatedBlocked)
+{
+ blockFeatureAttribute(theAttribute, myFeature, theToBlock, isFlushesActived,
+ isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked);
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::blockFeatureAttribute(const AttributePtr& theAttribute,
+ const FeaturePtr& theFeature,
+ const bool& theToBlock,
+ bool& isFlushesActived,
+ bool& isAttributeSetInitializedBlocked,
+ bool& isAttributeSendUpdatedBlocked)
{
Events_Loop* aLoop = Events_Loop::loop();
- DataPtr aData = myFeature->data();
+ DataPtr aData = theFeature->data();
if (theToBlock) {
// blocks the flush signals to avoid the temporary objects visualization in the viewer
// they should not be shown in order to do not lose highlight by erasing them
/// \return boolean value
bool isFilterActivated() const;
+ /// Block the model flush of update and intialization of attribute
+ /// \param theAttribute an attribute of blocking
+ /// \param theFeature a feature
+ /// \param theToBlock flag whether the model is blocked or unblocked
+ /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
+ /// to be used to restore flush state when unblocked
+ /// \param isAttributeSetInitializedBlocked out value if model is blocked
+ /// in value if model is unblocked to be used to restore previous state when unblocked
+ /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
+ static void blockFeatureAttribute(const AttributePtr& theAttribute,
+ const FeaturePtr& theFeature,
+ const bool& theToBlock,
+ bool& isFlushesActived,
+ bool& isAttributeSetInitializedBlocked,
+ bool& isAttributeSendUpdatedBlocked);
+
+ /// Checks the current attibute in all attribute validators
+ /// \param theAttribute an attribute to be validated
+ /// \return true if all validators return that the attribute is valid
+ static bool isValidAttribute(const AttributePtr& theAttribute);
+
protected:
/// Checks whether all active viewer filters validate the presentation
/// \param thePrs a selected presentation in the view
bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
bool& isAttributeSendUpdatedBlocked);
-private:
- /// Checks the current attibute in all attribute validators
- /// \param theAttribute an attribute to be validated
- /// \return true if all validators return that the attribute is valid
- bool isValidAttribute(const AttributePtr& theAttribute) const;
-
protected:
/// Gets the validity state of the presentation in an internal map.
/// Returns true if the valid state of value is stored
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
#include <ModuleBase_WidgetValidator.h>
+#include <ModuleBase_WidgetSelectorStore.h>
+#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_ViewerPrs.h>
ModuleBase_WidgetValidator::ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
ModuleBase_IWorkshop* theWorkshop)
-: myModelWidget(theModelWidget), myWorkshop(theWorkshop)
+: myModelWidget(theModelWidget), myWorkshop(theWorkshop), myIsInValidate(false)
{
+ myAttributeStore = new ModuleBase_WidgetSelectorStore();
}
ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
{
+ delete myAttributeStore;
}
//********************************************************************
return aHasSelectionFilter;
}
+void ModuleBase_WidgetValidator::storeAttributeValue(const AttributePtr& theAttribute)
+{
+ myIsInValidate = true;
+ myAttributeStore->storeAttributeValue(theAttribute, myWorkshop);
+}
+
+void ModuleBase_WidgetValidator::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
+{
+ myIsInValidate = false;
+ myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop);
+}
+
+bool ModuleBase_WidgetValidator::isValidAttribute(const AttributePtr& theAttribute) const
+{
+ return ModuleBase_WidgetValidated::isValidAttribute(theAttribute);
+}
+
bool ModuleBase_WidgetValidator::isFilterActivated() const
{
bool isActivated = false;
#include <QList>
#include <memory>
+class ModelAPI_Attribute;
+
class ModuleBase_ModelWidget;
class ModuleBase_IWorkshop;
class ModuleBase_ViewerPrs;
+class ModuleBase_WidgetSelectorStore;
/**
* \ingroup GUI
ModuleBase_IWorkshop* theWorkshop);
virtual ~ModuleBase_WidgetValidator();
+ /// Returns true if the validation is activated
+ bool isInValidate() const { return myIsInValidate; }
+
/// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
/// next, the attribute's validating. It trying on the give selection to current attribute by
/// setting the value inside and calling validators. After this, the previous attribute value is
/// \return true if the selection filter of the widget is activated in viewer context
bool activateFilters(const bool toActivate);
+ /// 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
+ /// \param theAttribute an attribute to be stored
+ virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
+
+ /// 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
+ /// \param theAttribute an attribute to be restored
+ /// \param theValid a boolean flag, if restore happens for valid parameters
+ virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
+ const bool theValid);
+
+ /// Checks the current attibute in all attribute validators
+ /// \param theAttribute an attribute to be validated
+ /// \return true if all validators return that the attribute is valid
+ bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
+
private:
/// Returns true if the workshop validator filter has been already activated
/// \return boolean value
void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
protected:
+ bool myIsInValidate; ///< cashed if the value is processed in validation
/// Reference to workshop
ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
+ ModuleBase_WidgetSelectorStore* myAttributeStore; //< store/restore attribute values
/// cash of valid selection presentations
QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
#include <ModuleBase_ISelection.h>
#include <ModuleBase_ViewerPrs.h>
#include <ModuleBase_WidgetValidator.h>
+#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_LabelValue.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
+#include <Events_InfoMessage.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeRefAttr.h>
return true;
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
- if (!aRefAttr.get()) {
+ if (aRefAttr.get())
+ return isValidSelectionForAttribute_(theValue, myFeature->attribute(attributeID()));
+ else {
bool aFoundPoint = false;
/// Avoid coincidence build to passed point. Coincidence is build later only if there are no
/// reference attribute.
return true;
}
+//********************************************************************
+bool PartSet_WidgetPoint2D::isValidSelectionForAttribute_(
+ const ModuleBase_ViewerPrsPtr& theValue,
+ const AttributePtr& theAttribute)
+{
+ bool aValid = false;
+
+ // stores the current values of the widget attribute
+ bool isFlushesActived, isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked;
+
+ AttributeRefAttrPtr aRefAttr = attributeRefAttr();
+ ModuleBase_WidgetValidated::blockFeatureAttribute(aRefAttr, myFeature, true,
+ isFlushesActived, isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked);
+ myWidgetValidator->storeAttributeValue(aRefAttr);
+
+ // saves the owner value to the widget attribute
+ aValid = setSelectionCustom(theValue);
+ if (aValid)
+ // checks the attribute validity
+ aValid = myWidgetValidator->isValidAttribute(theAttribute);
+
+ // restores the current values of the widget attribute
+ myWidgetValidator->restoreAttributeValue(aRefAttr, aValid);
+
+ ModuleBase_WidgetValidated::blockFeatureAttribute(aRefAttr, myFeature, false, isFlushesActived,
+ isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked);
+ return aValid;
+}
+
+bool PartSet_WidgetPoint2D::setSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
+{
+ bool isDone = false;
+ GeomShapePtr aShape = theValue->shape();
+ if (aShape.get() && !aShape->isNull()) {
+ Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
+ double aX, aY;
+ const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+ if (getPoint2d(aView, aTDShape, aX, aY)) {
+ fillRefAttribute(aX, aY);
+ isDone = true;
+ }
+ else if (aTDShape.ShapeType() == TopAbs_EDGE) {
+ fillRefAttribute(theValue->object());
+ isDone = true;
+ }
+ }
+ return isDone;
+}
+
bool PartSet_WidgetPoint2D::resetCustom()
{
bool aDone = false;
bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY)
{
- FeaturePtr aFeature = feature();
- std::string anAttribute = attributeID();
-
- if (!aFeature.get())
- return false;
-
- std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
- new GeomAPI_Pnt2d(theClickedX, theClickedY));
- AttributePoint2DPtr aClickedFeaturePoint = findFirstEqualPointInSketch(mySketch,
- aFeature, aClickedPoint);
- if (!aClickedFeaturePoint.get())
- return false;
-
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (aRefAttr.get())
- aRefAttr->setAttr(aClickedFeaturePoint);
+ fillRefAttribute(theClickedX, theClickedY);
else {
+ FeaturePtr aFeature = feature();
+ std::string anAttribute = attributeID();
+
+ if (!aFeature.get())
+ return false;
+
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+ new GeomAPI_Pnt2d(theClickedX, theClickedY));
+ AttributePoint2DPtr aClickedFeaturePoint = findFirstEqualPointInSketch(mySketch,
+ aFeature, aClickedPoint);
+ if (!aClickedFeaturePoint.get())
+ return false;
+
+ // aRefAttr->setAttr(aClickedFeaturePoint);
+ //else {
// find a feature point by the selection mode
AttributePoint2DPtr aFeaturePoint;
if (aFeature->isMacro()) {
{
AttributeRefAttrPtr aRefAttr = attributeRefAttr();
if (aRefAttr.get()) {
- aRefAttr->setObject(theObject);
+ fillRefAttribute(theObject);
}
else {
AttributePoint2DPtr aFeaturePoint;
return std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttributeRef);
}
+void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY)
+{
+ AttributeRefAttrPtr aRefAttr = attributeRefAttr();
+ if (!aRefAttr.get())
+ return;
+
+ FeaturePtr aFeature = feature();
+ std::string anAttribute = attributeID();
+
+ if (aFeature.get()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+ new GeomAPI_Pnt2d(theClickedX, theClickedY));
+ AttributePoint2DPtr aClickedFeaturePoint = findFirstEqualPointInSketch(mySketch,
+ aFeature, aClickedPoint);
+ if (aClickedFeaturePoint.get())
+ aRefAttr->setAttr(aClickedFeaturePoint);
+ }
+}
+
+void PartSet_WidgetPoint2D::fillRefAttribute(const ObjectPtr& theObject)
+{
+ AttributeRefAttrPtr aRefAttr = attributeRefAttr();
+ if (aRefAttr.get())
+ aRefAttr->setObject(theObject);
+}
+
std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPointInArgumentFeatures(
const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
{
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
// File: PartSet_WidgetPoint2d.h
// Created: 25 Apr 2014
/// \return a boolean value
virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+ /// Checks all attribute validators returns valid. It tries on the given selection
+ /// to current attribute by setting the value inside and calling validators. After this,
+ /// the previous attribute value is restored.The valid/invalid value is cashed.
+ /// \param theValue a selected presentation in the view
+ /// \param theAttribute the attribute
+ /// \return a boolean value
+ bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
+ const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
+
+ /// Fills the attribute with the value of the selected owner
+ /// \param thePrs a selected owner
+ bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
/// 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 widget values
/// \return found attribute or null
std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
+ /// Finds first equal point attribute in sketch and set it to reference attribute
+ /// \param theClickedX the horizontal coordnate of the point
+ /// \param theClickedY the vertical coordnate of the point
+ void fillRefAttribute(double theClickedX, double theClickedY);
+ void fillRefAttribute(const ObjectPtr& theObject);
+
protected:
ModuleBase_IWorkshop* myWorkshop; ///< workshop
if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aBaseShape));
- aStartPoint = anEdge->lastPoint();
- aLastPoint = anEdge->firstPoint();
+ //GeomAPI_Shape::Orientation anOrientation = anEdge->orientation();
+ //if (anOrientation == GeomAPI_Shape::REVERSED) {
+ aStartPoint = anEdge->lastPoint();
+ aLastPoint = anEdge->firstPoint();
+ //}
+ //else {
+ //aStartPoint = anEdge->firstPoint();
+ //aLastPoint = anEdge->lastPoint();
+ //}
}
}
}
}
#ifdef DEBUG_TRIM
std::cout << "<findShapePoints> => "
- << "Start Point: ["
- << aStartPoint->x() << ", " << aStartPoint->y() << ", " << aStartPoint->z() << "]"
- << "Last Point: ["
- << aLastPoint->x() << ", " << aLastPoint->y() << ", " << aLastPoint->z() << "]"
- << std::endl;
+ << std::endl << "Attribute point: "
+ << anAttributePnt->x() << ", " << anAttributePnt->y() << ", " << anAttributePnt->z() << "]"
+ << std::endl << "Start Point: ["
+ << aStartPoint->x() << ", " << aStartPoint->y() << ", " << aStartPoint->z() << "]"
+ << std::endl << "Last Point: ["
+ << aLastPoint->x() << ", " << aLastPoint->y() << ", " << aLastPoint->z() << "]"
+ << std::endl;
#endif
}
aFound = true;
}
else {
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- aPoint = thePoint->to2D(aPlane);
+ aPoint = sketch()->to2D(thePoint);
aFound = true;
}
}
if (!aFound) {
// returns an end of the shape to define direction of split if feature's attribute
// participates
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- aPoint = thePoint->to2D(aPlane);
+ aPoint = sketch()->to2D(thePoint);
}
return aPoint;
}
/// points of trim
std::shared_ptr<GeomAPI_Pnt> aStartShapePoint, aLastShapePoint;
+#ifdef DEBUG_TRIM
+ std::cout << " Base Feature: " << aBaseFeature->data()->name() << std::endl;
+#endif
findShapePoints(SELECTED_OBJECT(), SELECTED_POINT(), aStartShapePoint, aLastShapePoint);
+
std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
std::list<AttributePtr> aRefsToFeature;
getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
-
// coincidence to result points
// find coincidences to the base object, it should be used when attribute is found
// in myObjectToPoints
aFurtherCoincidences, aModifiedAttributes);
}
- //
+ // constraints to end points of trim feature
if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+ // create coincidence to objects, intersected the base object
const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
- std::set<AttributePoint2DPtr>::const_iterator anIt = aFurtherCoincidences.begin(),
- aLast = aFurtherCoincidences.end();
- for (; anIt != aLast; anIt++) {
+ for (std::set<AttributePoint2DPtr>::const_iterator anIt = aFurtherCoincidences.begin(),
+ aLast = aFurtherCoincidences.end();
+ anIt != aLast; anIt++) {
AttributePoint2DPtr aPointAttribute = (*anIt);
std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
+#ifdef DEBUG_TRIM
+ std::cout << "<compare Points> => "
+ << "aPoint2d: [" << aPoint2d->x() << ", " << aPoint2d->y() << "]" << std::endl;
+ if (aStartShapePoint2d.get())
+ std::cout << "Start Point: [" << aStartShapePoint2d->x() << ", " << aStartShapePoint2d->y()
+ << "]" << std::endl;
+ if (aLastShapePoint2d.get())
+ std::cout << "Last Point: [" << aLastShapePoint2d->x() << ", " << aLastShapePoint2d->y()
+ << "]" << std::endl;
+#endif
+
std::shared_ptr<GeomAPI_Pnt> aPoint;
if (aStartShapePoint2d.get() && aPoint2d->isEqual(aStartShapePoint2d))
aPoint = aStartShapePoint;
break;
}
}
- const std::list<AttributePoint2DPtr >& anAttributes = anInfo.first;
+ /*const std::list<AttributePoint2DPtr >& anAttributes = anInfo.first;
for (std::list<AttributePoint2DPtr>::const_iterator anAttrIt = anAttributes.begin();
anAttrIt != anAttributes.end(); anAttrIt++) {
AttributePtr anAttribute = *anAttrIt;
aRefAttr->setAttr(aPointAttribute);
}
}
-
+ */
const std::list<ObjectPtr>& anObjects = anInfo.second;
for (std::list<ObjectPtr>::const_iterator anObjectIt = anObjects.begin();
anObjectIt != anObjects.end(); anObjectIt++) {
// move constraints from base feature to replacing feature: ignore coincidences to feature
// if attributes of coincidence participated in split
+ ResultPtr aReplacingResult;
if (aReplacingFeature.get()) {
- ResultPtr aReplacingResult = getFeatureResult(aReplacingFeature);
- std::list<AttributePtr>::const_iterator anIt = aRefsToFeature.begin(),
- aLast = aRefsToFeature.end();
- for (; anIt != aLast; anIt++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
- if (!aRefAttr.get())
- continue;
- FeaturePtr anAttrFeature = ModelAPI_Feature::feature(aRefAttr->owner());
- if (anAttrFeature.get() &&
- anAttrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
- {
- if (anAttrFeature->attribute(SketchPlugin_Constraint::ENTITY_A()) == aRefAttr ||
- anAttrFeature->attribute(SketchPlugin_Constraint::ENTITY_B()) == aRefAttr)
- continue;
+ aReplacingFeature->execute(); // need it to obtain result
+ aReplacingResult = getFeatureResult(aReplacingFeature);
+ }
+ for(std::list<AttributePtr>::const_iterator anIt = aRefsToFeature.begin(),
+ aLast = aRefsToFeature.end();
+ anIt != aLast; anIt++) {
+ AttributePtr anAttribute = *anIt;
+ if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences))
+ continue;
+
+ if (aReplacingResult.get()) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
+ if (aRefAttr.get())
+ aRefAttr->setObject(aReplacingResult);
+ else {
+ AttributeReferencePtr aReferenceAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
+ if (aReferenceAttr.get())
+ aReferenceAttr->setObject(aReplacingResult);
}
- aRefAttr->setObject(aReplacingResult);
}
}
#endif
}
+bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribute,
+ const std::set<AttributePoint2DPtr>& theFurtherCoincidences)
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ return false;
+
+ AttributePoint2DPtr aRefPointAttr = SketchPlugin_ConstraintCoincidence::getPoint(aFeature);
+ if (!aRefPointAttr.get())
+ return false;
+ std::shared_ptr<GeomAPI_Pnt2d> aRefPnt2d = aRefPointAttr->pnt();
+
+ std::set<AttributePoint2DPtr>::const_iterator anIt = theFurtherCoincidences.begin(),
+ aLast = theFurtherCoincidences.end();
+ bool aFoundPoint = false;
+ for (; anIt != aLast && !aFoundPoint; anIt++) {
+ AttributePoint2DPtr aPointAttribute = (*anIt);
+ std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
+ if (aPoint2d->isEqual(aRefPnt2d)) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ theAttribute);
+ /*if (theAttribute->id() == SketchPlugin_ConstraintCoincidence::ENTITY_A())
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
+ else if (theAttribute->id() == SketchPlugin_ConstraintCoincidence::ENTITY_B())
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));*/
+ if (aRefAttr.get()) {
+ aRefAttr->setAttr(aPointAttribute);
+ aFoundPoint = true;
+ }
+ }
+ }
+ /*AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (!aRefAttr.get())
+ return false;
+
+ if (aRefAttr.get())
+ aRefAttr->setObject(aReplacingResult);//continue;
+ else {
+ //AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
+ AttributeReferencePtr aReferenceAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
+ }*/
+
+ return aFoundPoint;
+}
+
bool SketchPlugin_Trim::isMacro() const
{
return true;
anAttribute = aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
}
else {
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
(aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
if (aRefAttr->isObject() && aRefAttr->object() == theObject)
- {
anAttribute = aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_A());
- }
- if (anAttribute.get())
- {
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
- (anAttribute);
- anAttribute = aRefAttr->attr();
- if (anAttribute.get())
- theCoincidencesToBaseFeature[anAttribute] = aRefFeature;
- }
+ }
+ if (!anAttribute.get())
+ continue;
+
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
+ if (aRefAttr->isObject())
+ continue; // one of attributes of coincidence contains link to an attribute
+
+ anAttribute = aRefAttr->attr();
+ if (anAttribute.get())
+ {
+ theCoincidencesToBaseFeature[anAttribute] = aRefFeature;
}
}
}
(aBaseFeature->attribute(aModifiedAttribute)));
// equal Radius constraint for arcs
+ anArcFeature->execute(); // we need the created arc result to set equal constraint
createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
getFeatureResult(aBaseFeature),
getFeatureResult(anArcFeature));
/// trim feature
FeaturePtr anArcFeature = createArcFeature(aBaseFeature, theStartShapePoint, theLastShapePoint);
+ // arc created by trim of circle is always correct, that means that it is not inversed
+ anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(false);
theModifiedAttributes.insert(
std::make_pair(aBaseFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
return aFeature;
}
-
FeaturePtr SketchPlugin_Trim::createArcFeature(const FeaturePtr& theBaseFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed);
}
- aFeature->execute(); // to obtain result
+ //aFeature->execute(); // to obtain result
aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
return aFeature;
/// Moves the feature : Empty
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
+ bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
+ const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
+
typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
+++ /dev/null
-from salome.shaper import model
-
-from ModelAPI import *
-from GeomDataAPI import *
-from salome.shaper import geom
-import math
-
-TOLERANCE = 1.e-7
-
-SketchPointId = 'SketchPoint'
-SketchLineId = 'SketchLine'
-SketchArcId = 'SketchArc'
-SketchCircleId = 'SketchCircle'
-SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
-SketchConstraintMirrorId = 'SketchConstraintMirror'
-SketchConstraintTangentId = 'SketchConstraintTangent'
-SketchConstraintEqualId = 'SketchConstraintEqual'
-
-model.begin()
-partSet = model.moduleDocument()
-Part_1 = model.addPart(partSet)
-Part_1_doc = Part_1.document()
-
-# Test1:begin split on circle with coincident point and intersection line : smaller part
-Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchArc_1_1 = Sketch_1.addArc(50, 50, 55, 70, 30, 45, True)
-SketchLine_1_1 = Sketch_1.addLine(50, 30, 100, 30)
-SketchLine_1_2 = Sketch_1.addLine(60, 50, 100, 30)
-
-SketchConstraintCoincidence_1_1 = Sketch_1.setCoincident(SketchLine_1_1.startPoint(), SketchArc_1_1.results()[1])
-SketchConstraintCoincidence_1_2 = Sketch_1.setCoincident(SketchLine_1_1.endPoint(), SketchLine_1_2.endPoint())
-GeomPoint_1_1 = geom.Pnt2d(60, 35)
-
-#check number of features before trim
-Sketch_1_feature = featureToCompositeFeature(Sketch_1.feature())
-idList_before_1 = []
-for index in range(Sketch_1_feature.numberOfSubs()):
- idList_before_1.append(Sketch_1_feature.subFeature(index).getKind())
-assert(idList_before_1.count(SketchArcId) == 1)
-assert(idList_before_1.count(SketchLineId) == 2)
-assert(idList_before_1.count(SketchConstraintCoincidenceId) == 2)
-assert(idList_before_1.count(SketchConstraintEqualId) == 0)
-
-#perform trim
-SketchTrim_1_1 = Sketch_1.addTrim(SketchArc_1_1, GeomPoint_1_1)
-SketchTrim_1_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_1.feature())
-idList_after_1 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_1.append(SubFeature.getKind())
-
-assert(idList_after_1.count(SketchArcId) == 2)
-assert(idList_after_1.count(SketchLineId) == 2)
-aCount = idList_after_1.count(SketchConstraintCoincidenceId)
-
-assert(idList_after_1.count(SketchConstraintCoincidenceId) == 4)
-assert(idList_after_1.count(SketchConstraintEqualId) == 1)
-# Test1:end
-
-# Test2: split on circle with coincident point and intersection line : largest part
-Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-move_test_delta_y = 100
-move_test_delta_x = 0
-SketchCircle_2_1 = Sketch_2.addCircle(50, 50 + move_test_delta_y, 20)
-SketchLine_2_1 = Sketch_2.addLine(50, 30 + move_test_delta_y, 100, 30 + move_test_delta_y)
-SketchLine_2_2 = Sketch_2.addLine(60, 50 + move_test_delta_y, 100, 30 + move_test_delta_y)
-
-SketchConstraintCoincidence_2_1 = Sketch_2.setCoincident(SketchLine_2_1.startPoint(), SketchCircle_2_1.results()[1])
-SketchConstraintCoincidence_2_2 = Sketch_2.setCoincident(SketchLine_2_1.endPoint(), SketchLine_2_2.endPoint())
-GeomPoint_2_1 = geom.Pnt2d(50, 75 + move_test_delta_y)
-
-#check number of features before trim
-Sketch_2_feature = featureToCompositeFeature(Sketch_2.feature())
-idList_before_2 = []
-for index in range(Sketch_2_feature.numberOfSubs()):
- idList_before_2.append(Sketch_2_feature.subFeature(index).getKind())
-assert(idList_before_2.count(SketchCircleId) == 1)
-assert(idList_before_2.count(SketchArcId) == 0)
-assert(idList_before_2.count(SketchLineId) == 2)
-assert(idList_before_2.count(SketchConstraintCoincidenceId) == 2)
-
-#perform trim
-SketchTrim_2_1 = Sketch_2.addTrim(SketchCircle_2_1, GeomPoint_2_1)
-SketchTrim_2_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_2.feature())
-idList_after_2 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_2.append(SubFeature.getKind())
- if SubFeature.getKind() == SketchArcId:
- ArcFeature_2 = SubFeature
-
-
-assert(idList_after_2.count(SketchCircleId) == 0)
-assert(idList_after_2.count(SketchArcId) == 1)
-assert(idList_after_2.count(SketchLineId) == 2)
-assert(idList_after_2.count(SketchConstraintCoincidenceId) == 3)
-
-#test created arc : it is not inversed, has coincidence to start line point
-anInversed_2 = ArcFeature_2.boolean("InversedArc").value()
-assert(anInversed_2 == False)
-ArcPoint_2 = geomDataAPI_Point2D(ArcFeature_2.attribute("ArcStartPoint"))
-LinePoint_2 = geomDataAPI_Point2D(SketchLine_2_1.startPoint())
-aDistance_2 = math.hypot(LinePoint_2.x() - ArcPoint_2.x(), LinePoint_2.y() - ArcPoint_2.y())
-#print "Distance " + repr(aDistance_2)
-assert (math.fabs(aDistance_2) <= TOLERANCE)
-# Test2:end
-
-
-# Test3: constraints to circle
-Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchCircle_3_1 = Sketch_3.addCircle(150, 50, 25)
-SketchLine_3_1 = Sketch_3.addLine(160, 30, 200, 30)
-SketchLine_3_2 = Sketch_3.addLine(160, 50, 200, 30)
-SketchLine_3_3 = Sketch_3.addLine(240, 120, 280, 100)
-SketchCircle_3_2 = Sketch_3.addCircle(150, 120, 20)
-aSketchPoint_3 = Sketch_3.addPoint(145, 70)
-SketchLine_3_4 = Sketch_3.addLine(120, 25, 120, 70)
-
-SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchLine_3_1.startPoint(), SketchCircle_3_1.results()[1])
-SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchLine_3_1.endPoint(), SketchLine_3_2.endPoint())
-GeomPoint_3_1 = geom.Pnt2d(165, 40)
-
-#Constraints
-aConstraint_3_1 = Sketch_3.setDistance(SketchLine_3_1.endPoint(), SketchCircle_3_1.center(), 50)
-aConstraint_3_2 = Sketch_3.setEqual(SketchCircle_3_1.results()[1], SketchCircle_3_2.results()[1])
-aConstraint_3_3 = Sketch_3.setRadius(SketchCircle_3_1.results()[1], 25)
-aConstraint_3_4 = Sketch_3.setCoincident(SketchCircle_3_1.results()[1], aSketchPoint_3.results()[0])
-aConstraint_3_4 = Sketch_3.setTangent(SketchCircle_3_1.results()[1], SketchLine_3_4.results()[0])
-
-MirrorObjects_3 = [SketchCircle_3_1.results()[1], SketchCircle_3_2.results()[1]]
-aConstraint_3_5 = Sketch_3.addMirror(SketchLine_3_3.result(), MirrorObjects_3)
-
-#check number of features before trim
-Sketch_3_feature = featureToCompositeFeature(Sketch_3.feature())
-idList_before_3 = []
-for index in range(Sketch_3_feature.numberOfSubs()):
- idList_before_3.append(Sketch_3_feature.subFeature(index).getKind())
-
-assert(idList_before_3.count(SketchCircleId) == 4)
-assert(idList_before_3.count(SketchArcId) == 0)
-assert(idList_before_3.count(SketchLineId) == 4)
-assert(idList_before_3.count(SketchConstraintCoincidenceId) == 3)
-assert(idList_before_3.count(SketchConstraintMirrorId) == 1)
-assert(idList_before_3.count(SketchConstraintTangentId) == 1)
-assert(idList_before_3.count(SketchConstraintEqualId) == 1)
-
-#perform trim
-SketchTrim_3_1 = Sketch_3.addTrim(SketchCircle_3_1, GeomPoint_3_1)
-SketchTrim_3_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_3.feature())
-idList_after_3 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_3.append(SubFeature.getKind())
-
-
-assert(idList_after_3.count(SketchCircleId) == 3)
-assert(idList_after_3.count(SketchArcId) == 1)
-assert(idList_after_3.count(SketchLineId) == 4)
-assert(idList_after_3.count(SketchConstraintCoincidenceId) == 3)
-assert(idList_after_3.count(SketchConstraintMirrorId) == 0)
-assert(idList_after_3.count(SketchConstraintTangentId) == 1)
-assert(idList_after_3.count(SketchConstraintEqualId) == 1)
-# Test3:end
-
-
-model.end()
-
-#assert(model.checkPythonDump())
+++ /dev/null
-from salome.shaper import model
-
-from ModelAPI import *
-from GeomDataAPI import *
-from salome.shaper import geom
-import math
-
-TOLERANCE = 1.e-7
-
-SketchPointId = 'SketchPoint'
-SketchLineId = 'SketchLine'
-SketchArcId = 'SketchArc'
-SketchCircleId = 'SketchCircle'
-SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
-SketchConstraintMirrorId = 'SketchConstraintMirror'
-SketchConstraintTangentId = 'SketchConstraintTangent'
-SketchConstraintEqualId = 'SketchConstraintEqual'
-
-model.begin()
-partSet = model.moduleDocument()
-Part_1 = model.addPart(partSet)
-Part_1_doc = Part_1.document()
-
-# Test1:begin split on circle with coincident point and intersection line : smaller part
-Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchCircle_1_1 = Sketch_1.addCircle(50, 50, 20)
-SketchLine_1_1 = Sketch_1.addLine(50, 30, 100, 30)
-SketchLine_1_2 = Sketch_1.addLine(60, 50, 100, 30)
-
-SketchConstraintCoincidence_1_1 = Sketch_1.setCoincident(SketchLine_1_1.startPoint(), SketchCircle_1_1.results()[1])
-SketchConstraintCoincidence_1_2 = Sketch_1.setCoincident(SketchLine_1_1.endPoint(), SketchLine_1_2.endPoint())
-GeomPoint_1_1 = geom.Pnt2d(60, 35)
-
-#check number of features before trim
-Sketch_1_feature = featureToCompositeFeature(Sketch_1.feature())
-idList_before_1 = []
-for index in range(Sketch_1_feature.numberOfSubs()):
- idList_before_1.append(Sketch_1_feature.subFeature(index).getKind())
-assert(idList_before_1.count(SketchCircleId) == 1)
-assert(idList_before_1.count(SketchArcId) == 0)
-assert(idList_before_1.count(SketchLineId) == 2)
-assert(idList_before_1.count(SketchConstraintCoincidenceId) == 2)
-
-#perform trim
-SketchTrim_1_1 = Sketch_1.addTrim(SketchCircle_1_1, GeomPoint_1_1)
-SketchTrim_1_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_1.feature())
-idList_after_1 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_1.append(SubFeature.getKind())
- if SubFeature.getKind() == SketchArcId:
- ArcFeature_1 = SubFeature
-
-
-assert(idList_after_1.count(SketchCircleId) == 0)
-assert(idList_after_1.count(SketchArcId) == 1)
-assert(idList_after_1.count(SketchLineId) == 2)
-assert(idList_after_1.count(SketchConstraintCoincidenceId) == 3)
-
-#test created arc: it is not inversed, has coincidence to end line point
-anInversed_1 = ArcFeature_1.boolean("InversedArc").value()
-assert(anInversed_1 == False)
-ArcPoint_1 = geomDataAPI_Point2D(ArcFeature_1.attribute("ArcEndPoint"))
-LinePoint_1 = geomDataAPI_Point2D(SketchLine_1_1.startPoint())
-aDistance_1 = math.hypot(LinePoint_1.x() - ArcPoint_1.x(), LinePoint_1.y() - ArcPoint_1.y())
-#print "Distance " + repr(aDistance)
-assert (math.fabs(aDistance_1) <= TOLERANCE)
-# Test1:end
-
-
-# Test2: split on circle with coincident point and intersection line : largest part
-Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-move_test_delta_y = 100
-move_test_delta_x = 0
-SketchCircle_2_1 = Sketch_2.addCircle(50, 50 + move_test_delta_y, 20)
-SketchLine_2_1 = Sketch_2.addLine(50, 30 + move_test_delta_y, 100, 30 + move_test_delta_y)
-SketchLine_2_2 = Sketch_2.addLine(60, 50 + move_test_delta_y, 100, 30 + move_test_delta_y)
-
-SketchConstraintCoincidence_2_1 = Sketch_2.setCoincident(SketchLine_2_1.startPoint(), SketchCircle_2_1.results()[1])
-SketchConstraintCoincidence_2_2 = Sketch_2.setCoincident(SketchLine_2_1.endPoint(), SketchLine_2_2.endPoint())
-GeomPoint_2_1 = geom.Pnt2d(50, 75 + move_test_delta_y)
-
-#check number of features before trim
-Sketch_2_feature = featureToCompositeFeature(Sketch_2.feature())
-idList_before_2 = []
-for index in range(Sketch_2_feature.numberOfSubs()):
- idList_before_2.append(Sketch_2_feature.subFeature(index).getKind())
-assert(idList_before_2.count(SketchCircleId) == 1)
-assert(idList_before_2.count(SketchArcId) == 0)
-assert(idList_before_2.count(SketchLineId) == 2)
-assert(idList_before_2.count(SketchConstraintCoincidenceId) == 2)
-
-#perform trim
-SketchTrim_2_1 = Sketch_2.addTrim(SketchCircle_2_1, GeomPoint_2_1)
-SketchTrim_2_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_2.feature())
-idList_after_2 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_2.append(SubFeature.getKind())
- if SubFeature.getKind() == SketchArcId:
- ArcFeature_2 = SubFeature
-
-
-assert(idList_after_2.count(SketchCircleId) == 0)
-assert(idList_after_2.count(SketchArcId) == 1)
-assert(idList_after_2.count(SketchLineId) == 2)
-assert(idList_after_2.count(SketchConstraintCoincidenceId) == 3)
-
-#test created arc : it is not inversed, has coincidence to start line point
-anInversed_2 = ArcFeature_2.boolean("InversedArc").value()
-assert(anInversed_2 == False)
-ArcPoint_2 = geomDataAPI_Point2D(ArcFeature_2.attribute("ArcStartPoint"))
-LinePoint_2 = geomDataAPI_Point2D(SketchLine_2_1.startPoint())
-aDistance_2 = math.hypot(LinePoint_2.x() - ArcPoint_2.x(), LinePoint_2.y() - ArcPoint_2.y())
-#print "Distance " + repr(aDistance_2)
-assert (math.fabs(aDistance_2) <= TOLERANCE)
-# Test2:end
-
-
-# Test3: constraints to circle
-Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchCircle_3_1 = Sketch_3.addCircle(150, 50, 25)
-SketchLine_3_1 = Sketch_3.addLine(160, 30, 200, 30)
-SketchLine_3_2 = Sketch_3.addLine(160, 50, 200, 30)
-SketchLine_3_3 = Sketch_3.addLine(240, 120, 280, 100)
-SketchCircle_3_2 = Sketch_3.addCircle(150, 120, 20)
-aSketchPoint_3 = Sketch_3.addPoint(145, 70)
-SketchLine_3_4 = Sketch_3.addLine(120, 25, 120, 70)
-
-SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchLine_3_1.startPoint(), SketchCircle_3_1.results()[1])
-SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchLine_3_1.endPoint(), SketchLine_3_2.endPoint())
-GeomPoint_3_1 = geom.Pnt2d(165, 40)
-
-#Constraints
-aConstraint_3_1 = Sketch_3.setDistance(SketchLine_3_1.endPoint(), SketchCircle_3_1.center(), 50)
-aConstraint_3_2 = Sketch_3.setEqual(SketchCircle_3_1.results()[1], SketchCircle_3_2.results()[1])
-aConstraint_3_3 = Sketch_3.setRadius(SketchCircle_3_1.results()[1], 25)
-aConstraint_3_4 = Sketch_3.setCoincident(SketchCircle_3_1.results()[1], aSketchPoint_3.results()[0])
-aConstraint_3_4 = Sketch_3.setTangent(SketchCircle_3_1.results()[1], SketchLine_3_4.results()[0])
-
-MirrorObjects_3 = [SketchCircle_3_1.results()[1], SketchCircle_3_2.results()[1]]
-aConstraint_3_5 = Sketch_3.addMirror(SketchLine_3_3.result(), MirrorObjects_3)
-
-#check number of features before trim
-Sketch_3_feature = featureToCompositeFeature(Sketch_3.feature())
-idList_before_3 = []
-for index in range(Sketch_3_feature.numberOfSubs()):
- idList_before_3.append(Sketch_3_feature.subFeature(index).getKind())
-
-assert(idList_before_3.count(SketchCircleId) == 4)
-assert(idList_before_3.count(SketchArcId) == 0)
-assert(idList_before_3.count(SketchLineId) == 4)
-assert(idList_before_3.count(SketchConstraintCoincidenceId) == 3)
-assert(idList_before_3.count(SketchConstraintMirrorId) == 1)
-assert(idList_before_3.count(SketchConstraintTangentId) == 1)
-assert(idList_before_3.count(SketchConstraintEqualId) == 1)
-
-#perform trim
-SketchTrim_3_1 = Sketch_3.addTrim(SketchCircle_3_1, GeomPoint_3_1)
-SketchTrim_3_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_3.feature())
-idList_after_3 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_3.append(SubFeature.getKind())
-
-
-assert(idList_after_3.count(SketchCircleId) == 3)
-assert(idList_after_3.count(SketchArcId) == 1)
-assert(idList_after_3.count(SketchLineId) == 4)
-assert(idList_after_3.count(SketchConstraintCoincidenceId) == 3)
-assert(idList_after_3.count(SketchConstraintMirrorId) == 0)
-assert(idList_after_3.count(SketchConstraintTangentId) == 1)
-assert(idList_after_3.count(SketchConstraintEqualId) == 1)
-# Test3:end
-
-
-model.end()
-
-#assert(model.checkPythonDump())
+++ /dev/null
-from salome.shaper import model
-
-from ModelAPI import *
-from GeomDataAPI import *
-from salome.shaper import geom
-import math
-
-TOLERANCE = 1.e-7
-
-SketchPointId = 'SketchPoint'
-SketchLineId = 'SketchLine'
-SketchArcId = 'SketchArc'
-SketchCircleId = 'SketchCircle'
-SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
-SketchConstraintMirrorId = 'SketchConstraintMirror'
-SketchConstraintTangentId = 'SketchConstraintTangent'
-SketchConstraintEqualId = 'SketchConstraintEqual'
-
-model.begin()
-partSet = model.moduleDocument()
-Part_1 = model.addPart(partSet)
-Part_1_doc = Part_1.document()
-
-# Test1:begin split on circle with coincident point and intersection line : smaller part
-Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchCircle_1_1 = Sketch_1.addCircle(50, 50, 20)
-SketchLine_1_1 = Sketch_1.addLine(50, 30, 100, 30)
-SketchLine_1_2 = Sketch_1.addLine(60, 50, 100, 30)
-
-SketchConstraintCoincidence_1_1 = Sketch_1.setCoincident(SketchLine_1_1.startPoint(), SketchCircle_1_1.results()[1])
-SketchConstraintCoincidence_1_2 = Sketch_1.setCoincident(SketchLine_1_1.endPoint(), SketchLine_1_2.endPoint())
-GeomPoint_1_1 = geom.Pnt2d(60, 35)
-
-#check number of features before trim
-Sketch_1_feature = featureToCompositeFeature(Sketch_1.feature())
-idList_before_1 = []
-for index in range(Sketch_1_feature.numberOfSubs()):
- idList_before_1.append(Sketch_1_feature.subFeature(index).getKind())
-assert(idList_before_1.count(SketchCircleId) == 1)
-assert(idList_before_1.count(SketchArcId) == 0)
-assert(idList_before_1.count(SketchLineId) == 2)
-assert(idList_before_1.count(SketchConstraintCoincidenceId) == 2)
-
-#perform trim
-SketchTrim_1_1 = Sketch_1.addTrim(SketchCircle_1_1, GeomPoint_1_1)
-SketchTrim_1_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_1.feature())
-idList_after_1 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_1.append(SubFeature.getKind())
- if SubFeature.getKind() == SketchArcId:
- ArcFeature_1 = SubFeature
-
-
-assert(idList_after_1.count(SketchCircleId) == 0)
-assert(idList_after_1.count(SketchArcId) == 1)
-assert(idList_after_1.count(SketchLineId) == 2)
-assert(idList_after_1.count(SketchConstraintCoincidenceId) == 3)
-
-#test created arc: it is not inversed, has coincidence to end line point
-anInversed_1 = ArcFeature_1.boolean("InversedArc").value()
-assert(anInversed_1 == False)
-ArcPoint_1 = geomDataAPI_Point2D(ArcFeature_1.attribute("ArcEndPoint"))
-LinePoint_1 = geomDataAPI_Point2D(SketchLine_1_1.startPoint())
-aDistance_1 = math.hypot(LinePoint_1.x() - ArcPoint_1.x(), LinePoint_1.y() - ArcPoint_1.y())
-#print "Distance " + repr(aDistance)
-assert (math.fabs(aDistance_1) <= TOLERANCE)
-# Test1:end
-
-
-# Test2: split on circle with coincident point and intersection line : largest part
-Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-move_test_delta_y = 100
-move_test_delta_x = 0
-SketchCircle_2_1 = Sketch_2.addCircle(50, 50 + move_test_delta_y, 20)
-SketchLine_2_1 = Sketch_2.addLine(50, 30 + move_test_delta_y, 100, 30 + move_test_delta_y)
-SketchLine_2_2 = Sketch_2.addLine(60, 50 + move_test_delta_y, 100, 30 + move_test_delta_y)
-
-SketchConstraintCoincidence_2_1 = Sketch_2.setCoincident(SketchLine_2_1.startPoint(), SketchCircle_2_1.results()[1])
-SketchConstraintCoincidence_2_2 = Sketch_2.setCoincident(SketchLine_2_1.endPoint(), SketchLine_2_2.endPoint())
-GeomPoint_2_1 = geom.Pnt2d(50, 75 + move_test_delta_y)
-
-#check number of features before trim
-Sketch_2_feature = featureToCompositeFeature(Sketch_2.feature())
-idList_before_2 = []
-for index in range(Sketch_2_feature.numberOfSubs()):
- idList_before_2.append(Sketch_2_feature.subFeature(index).getKind())
-assert(idList_before_2.count(SketchCircleId) == 1)
-assert(idList_before_2.count(SketchArcId) == 0)
-assert(idList_before_2.count(SketchLineId) == 2)
-assert(idList_before_2.count(SketchConstraintCoincidenceId) == 2)
-
-#perform trim
-SketchTrim_2_1 = Sketch_2.addTrim(SketchCircle_2_1, GeomPoint_2_1)
-SketchTrim_2_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_2.feature())
-idList_after_2 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_2.append(SubFeature.getKind())
- if SubFeature.getKind() == SketchArcId:
- ArcFeature_2 = SubFeature
-
-
-assert(idList_after_2.count(SketchCircleId) == 0)
-assert(idList_after_2.count(SketchArcId) == 1)
-assert(idList_after_2.count(SketchLineId) == 2)
-assert(idList_after_2.count(SketchConstraintCoincidenceId) == 3)
-
-#test created arc : it is not inversed, has coincidence to start line point
-anInversed_2 = ArcFeature_2.boolean("InversedArc").value()
-assert(anInversed_2 == False)
-ArcPoint_2 = geomDataAPI_Point2D(ArcFeature_2.attribute("ArcStartPoint"))
-LinePoint_2 = geomDataAPI_Point2D(SketchLine_2_1.startPoint())
-aDistance_2 = math.hypot(LinePoint_2.x() - ArcPoint_2.x(), LinePoint_2.y() - ArcPoint_2.y())
-#print "Distance " + repr(aDistance_2)
-assert (math.fabs(aDistance_2) <= TOLERANCE)
-# Test2:end
-
-
-# Test3: constraints to circle
-Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
-SketchCircle_3_1 = Sketch_3.addCircle(150, 50, 25)
-SketchLine_3_1 = Sketch_3.addLine(160, 30, 200, 30)
-SketchLine_3_2 = Sketch_3.addLine(160, 50, 200, 30)
-SketchLine_3_3 = Sketch_3.addLine(240, 120, 280, 100)
-SketchCircle_3_2 = Sketch_3.addCircle(150, 120, 20)
-aSketchPoint_3 = Sketch_3.addPoint(145, 70)
-SketchLine_3_4 = Sketch_3.addLine(120, 25, 120, 70)
-
-SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchLine_3_1.startPoint(), SketchCircle_3_1.results()[1])
-SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchLine_3_1.endPoint(), SketchLine_3_2.endPoint())
-GeomPoint_3_1 = geom.Pnt2d(165, 40)
-
-#Constraints
-aConstraint_3_1 = Sketch_3.setDistance(SketchLine_3_1.endPoint(), SketchCircle_3_1.center(), 50)
-aConstraint_3_2 = Sketch_3.setEqual(SketchCircle_3_1.results()[1], SketchCircle_3_2.results()[1])
-aConstraint_3_3 = Sketch_3.setRadius(SketchCircle_3_1.results()[1], 25)
-aConstraint_3_4 = Sketch_3.setCoincident(SketchCircle_3_1.results()[1], aSketchPoint_3.results()[0])
-aConstraint_3_4 = Sketch_3.setTangent(SketchCircle_3_1.results()[1], SketchLine_3_4.results()[0])
-
-MirrorObjects_3 = [SketchCircle_3_1.results()[1], SketchCircle_3_2.results()[1]]
-aConstraint_3_5 = Sketch_3.addMirror(SketchLine_3_3.result(), MirrorObjects_3)
-
-#check number of features before trim
-Sketch_3_feature = featureToCompositeFeature(Sketch_3.feature())
-idList_before_3 = []
-for index in range(Sketch_3_feature.numberOfSubs()):
- idList_before_3.append(Sketch_3_feature.subFeature(index).getKind())
-
-assert(idList_before_3.count(SketchCircleId) == 4)
-assert(idList_before_3.count(SketchArcId) == 0)
-assert(idList_before_3.count(SketchLineId) == 4)
-assert(idList_before_3.count(SketchConstraintCoincidenceId) == 3)
-assert(idList_before_3.count(SketchConstraintMirrorId) == 1)
-assert(idList_before_3.count(SketchConstraintTangentId) == 1)
-assert(idList_before_3.count(SketchConstraintEqualId) == 1)
-
-#perform trim
-SketchTrim_3_1 = Sketch_3.addTrim(SketchCircle_3_1, GeomPoint_3_1)
-SketchTrim_3_1.execute()
-model.do()
-
-#check number of features after trim
-SketchFeatures = featureToCompositeFeature(Sketch_3.feature())
-idList_after_3 = []
-for SubIndex in range(SketchFeatures.numberOfSubs()):
- SubFeature = SketchFeatures.subFeature(SubIndex)
- idList_after_3.append(SubFeature.getKind())
-
-
-assert(idList_after_3.count(SketchCircleId) == 3)
-assert(idList_after_3.count(SketchArcId) == 1)
-assert(idList_after_3.count(SketchLineId) == 4)
-assert(idList_after_3.count(SketchConstraintCoincidenceId) == 3)
-assert(idList_after_3.count(SketchConstraintMirrorId) == 0)
-assert(idList_after_3.count(SketchConstraintTangentId) == 1)
-assert(idList_after_3.count(SketchConstraintEqualId) == 1)
-# Test3:end
-
-
-model.end()
-
-#assert(model.checkPythonDump())