-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 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
//
// 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
+// 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>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SketchPlugin_Trim.h"
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_ConstraintEqual.h>
-//#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintMirror.h>
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Projection.h>
+#include <SketchPlugin_Tools.h>
#include <ModelAPI_EventReentrantMessage.h>
#include <cmath>
-//#define DEBUG_TRIM_METHODS
-//#define DEBUG_TRIM
-
#ifdef DEBUG_TRIM
#include <iostream>
#endif
std::cout << " Base Feature: " << aBaseFeature->data()->name() << std::endl;
#endif
findShapePoints(SELECTED_OBJECT(), SELECTED_POINT(), aStartShapePoint, aLastShapePoint);
+ if (!aStartShapePoint || !aLastShapePoint) {
+ setError("Error: Selected point is not placed on any edge");
+ return;
+ }
std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
std::cout << "[" << aRefsToFeature.size() << "] " << aRefsInfo << std::endl;
std::cout << "---- getRefAttributes:end ----" << std::endl;
#endif
+
+ keepCurrentFeature();
+
std::set<AttributePoint2DPtr> aFurtherCoincidences;
std::set<std::pair<AttributePtr, AttributePtr>> aModifiedAttributes;
const std::string& aKind = aBaseFeature->getKind();
aFurtherCoincidences, aModifiedAttributes);
}
+ restoreCurrentFeature();
+
// constraints to end points of trim feature
if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
const std::list<ObjectPtr>& anObjects = anInfo.second;
for (std::list<ObjectPtr>::const_iterator anObjectIt = anObjects.begin();
anObjectIt != anObjects.end(); anObjectIt++) {
- createConstraintToObject(SketchPlugin_ConstraintCoincidence::ID(), aPointAttribute,
- *anObjectIt);
+ SketchPlugin_Tools::createConstraintAttrObject(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
+ aPointAttribute, *anObjectIt);
}
}
anIt != aLast; anIt++) {
AttributePtr anAttribute = *anIt;
- if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences))
+ if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences, aFeaturesToDelete))
continue;
// move tangency constraint to the nearest feature if possible
#endif
}
+// LCOV_EXCL_START
std::string SketchPlugin_Trim::processEvent(const std::shared_ptr<Events_Message>& theMessage)
{
#ifdef DEBUG_TRIM_METHODS
}
return aFilledAttributeName;
}
+// LCOV_EXCL_STOP
bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribute,
- const std::set<AttributePoint2DPtr>& theFurtherCoincidences)
+ const std::set<AttributePoint2DPtr>& theFurtherCoincidences,
+ std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete)
{
FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
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 (aRefAttr.get()) {
- aRefAttr->setAttr(aPointAttribute);
- aFoundPoint = true;
- }
+ // create new coincidence and then remove the old one
+ SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
+ aRefPointAttr, aPointAttribute);
+ theFeaturesToDelete.insert(aFeature);
}
}
return aFoundPoint;
(aBaseFeature->attribute(aModifiedAttribute)));
// Collinear constraint for lines
- createConstraintForObjects(SketchPlugin_ConstraintCollinear::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(anNewFeature));
-
+ SketchPlugin_Tools::createConstraintObjectObject(sketch(),
+ SketchPlugin_ConstraintCollinear::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(anNewFeature));
}
return anNewFeature;
}
(aBaseFeature->attribute(aModifiedAttribute)));
// equal Radius constraint for arcs
- createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(anNewFeature));
+ SketchPlugin_Tools::createConstraintObjectObject(sketch(),
+ SketchPlugin_ConstraintEqual::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(anNewFeature));
// coincident centers constraint
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
- aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
- anNewFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+ SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
+ aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
+ anNewFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
#ifdef DEBUG_TRIM
std::cout << "Created arc on points:" << std::endl;
if (aModifiedAttribute.get() && aSourceAttribute.get())
aModifiedAttribute->setValue(aSourceAttribute->value());
}
- else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttributeToFill = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- theModifiedAttribute);
- AttributeRefAttrPtr aSourceRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- theSourceAttribute);
- if (!aSourceRefAttr.get())
- aRefAttributeToFill->setAttr(theSourceAttribute);
- else {
- if (aSourceRefAttr->isObject())
- aRefAttributeToFill->setObject(aSourceRefAttr->object());
- else
- aRefAttributeToFill->setAttr(aSourceRefAttr->attr());
- }
- }
}
FeaturePtr SketchPlugin_Trim::createLineFeature(const FeaturePtr& theBaseFeature,
return aFeature;
}
-FeaturePtr SketchPlugin_Trim::createConstraint(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const AttributePtr& theSecondAttribute)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(theSecondAttribute);
-
-#ifdef DEBUG_TRIM
- std::cout << "<createConstraint to attribute> :"
- << "first attribute - " << theFirstAttribute->id()
- << "second attribute - " << theSecondAttribute->id()
- << std::endl;
-#endif
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraintToObject(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
-#ifdef DEBUG_TRIM
- std::cout << "<createConstraint to attribute> :"
- << "first attribute - " << theFirstAttribute->id()
- << "second object - " << ModelAPI_Feature::feature(theSecondObject)->getKind()
- << std::endl;
-#endif
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraintForObjects(
- const std::string& theConstraintId,
- const ObjectPtr& theFirstObject,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setObject(theFirstObject);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
- return aConstraint;
-}
-
std::shared_ptr<ModelAPI_Result> SketchPlugin_Trim::getFeatureResult(
const std::shared_ptr<ModelAPI_Feature>& theFeature)
{
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
for (int i = 0; i < aSketchComposite->numberOfSubs(); i++) {
FeaturePtr aFeature = aSketchComposite->subFeature(i);
- if (aFeature.get())
+ if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
aFeatures.push_back(aFeature);
}
ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);