X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketchPlugin%2FSketchPlugin_Trim.cpp;h=387f3a8b4e9edaf2ccfcffc9263c3f0b0066b81d;hb=6a9eb86984ff6892c0dd95700ee6f37e5235c10e;hp=53a4ad23c56858b5ed08ec5c3fc13206eefe95ab;hpb=021afd7f7f69143c014d060924dd987849768b1e;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index 53a4ad23c..387f3a8b4 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: SketchPlugin_Trim.cpp -// Created: 22 Feb 2017 -// Author: Natalia ERMOLAEVA +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include "SketchPlugin_Trim.h" @@ -31,7 +45,6 @@ #include #include #include -//#include #include #include #include @@ -40,6 +53,8 @@ #include #include #include +#include +#include #include @@ -53,9 +68,6 @@ #include -//#define DEBUG_TRIM_METHODS -//#define DEBUG_TRIM - #ifdef DEBUG_TRIM #include #endif @@ -347,8 +359,9 @@ void SketchPlugin_Trim::execute() const std::list& anObjects = anInfo.second; for (std::list::const_iterator anObjectIt = anObjects.begin(); anObjectIt != anObjects.end(); anObjectIt++) { - createConstraintToObject(SketchPlugin_ConstraintCoincidence::ID(), aPointAttribute, - *anObjectIt); + SketchPlugin_Tools::createConstraintAttrObject(sketch(), + SketchPlugin_ConstraintCoincidence::ID(), + aPointAttribute, *anObjectIt); } } @@ -364,7 +377,7 @@ void SketchPlugin_Trim::execute() 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 @@ -518,7 +531,8 @@ std::string SketchPlugin_Trim::processEvent(const std::shared_ptr& theFurtherCoincidences) + const std::set& theFurtherCoincidences, + std::set>& theFeaturesToDelete) { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID()) @@ -536,12 +550,11 @@ bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribu AttributePoint2DPtr aPointAttribute = (*anIt); std::shared_ptr aPoint2d = aPointAttribute->pnt(); if (aPoint2d->isEqual(aRefPnt2d)) { - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast( - 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; @@ -951,10 +964,10 @@ FeaturePtr SketchPlugin_Trim::trimLine(const std::shared_ptr& the (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; } @@ -1036,13 +1049,15 @@ FeaturePtr SketchPlugin_Trim::trimArc(const std::shared_ptr& theS (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; @@ -1279,69 +1294,6 @@ FeaturePtr SketchPlugin_Trim::createArcFeature(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( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttr->setAttr(theFirstAttribute); - - aRefAttr = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); - aRefAttr->setAttr(theSecondAttribute); - -#ifdef DEBUG_TRIM - std::cout << " :" - << "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( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttr->setAttr(theFirstAttribute); - - aRefAttr = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); - aRefAttr->setObject(theSecondObject); - -#ifdef DEBUG_TRIM - std::cout << " :" - << "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( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttr->setObject(theFirstObject); - - aRefAttr = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); - aRefAttr->setObject(theSecondObject); - - return aConstraint; -} - std::shared_ptr SketchPlugin_Trim::getFeatureResult( const std::shared_ptr& theFeature) { @@ -1402,7 +1354,7 @@ void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject, std::dynamic_pointer_cast(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);