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;