X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Group.cpp;h=3ea7ade275d687c30a4c4f64ee4fbbcfe8a2313b;hb=05c54697df5d6968704e869a4a21102a0477121f;hp=6e2e4ed6e83a57a4f4571abacc19fc38679d7228;hpb=97917d3698f5a2f7fc9596e7c755ff8f6751e373;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 6e2e4ed6e..3ea7ade27 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 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 @@ -33,6 +33,8 @@ #include #include +#include + static void sendMessage(const char* theMessageName) { @@ -73,14 +75,14 @@ static void sendMessage(const char* theMessageName, // ======================================================== SketchSolver_Group::SketchSolver_Group(const CompositeFeaturePtr& theWorkplane) - : mySketch(theWorkplane), - myPrevResult(PlaneGCSSolver_Solver::STATUS_UNKNOWN), + : myPrevResult(PlaneGCSSolver_Solver::STATUS_UNKNOWN), myDOF(-1), myIsEventsBlocked(false), myMultiConstraintUpdateStack(0) { mySketchSolver = SolverPtr(new PlaneGCSSolver_Solver); myStorage = StoragePtr(new PlaneGCSSolver_Storage(mySketchSolver)); + updateSketch(theWorkplane); } SketchSolver_Group::~SketchSolver_Group() @@ -123,6 +125,34 @@ bool SketchSolver_Group::changeConstraint( return true; } +bool SketchSolver_Group::updateSketch(CompositeFeaturePtr theSketch) +{ + static const double THE_TOLERANCE = 1.e-7; + bool isChanged = theSketch != mySketch; + + AttributePointPtr anOrigin = std::dynamic_pointer_cast( + theSketch->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + AttributeDirPtr aNorm = std::dynamic_pointer_cast( + theSketch->attribute(SketchPlugin_Sketch::NORM_ID())); + AttributeDirPtr aDirX = std::dynamic_pointer_cast( + theSketch->attribute(SketchPlugin_Sketch::DIRX_ID())); + + isChanged = isChanged + || (mySketchOrigin && anOrigin && anOrigin->pnt()->distance(mySketchOrigin) > THE_TOLERANCE) + || (mySketchNormal && aNorm && aNorm->xyz()->distance(mySketchNormal->xyz()) > THE_TOLERANCE) + || (mySketchXDir && aDirX && aDirX->xyz()->distance(mySketchXDir->xyz()) > THE_TOLERANCE); + + if (isChanged) { + mySketch = theSketch; + mySketchOrigin = anOrigin->pnt(); + mySketchNormal = aNorm->dir(); + mySketchXDir = aDirX->dir(); + + myStorage->notify(theSketch); + } + return true; +} + bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) { return myStorage->update(theFeature); @@ -134,10 +164,11 @@ static SolverConstraintPtr move(StoragePtr theStorage, int theSketchDOF, bool theEventsBlocked, Type theFeatureOrPoint, + const EntityWrapperPtr& theSolverEntity, const std::shared_ptr& theFrom, const std::shared_ptr& theTo) { - bool isEntityExists = (theStorage->entity(theFeatureOrPoint).get() != 0); + bool isEntityExists = (theSolverEntity.get() != 0); if (theSketchDOF == 0 && isEntityExists) { // avoid moving elements of fully constrained sketch theStorage->refresh(); @@ -151,6 +182,7 @@ static SolverConstraintPtr move(StoragePtr theStorage, SolverConstraintPtr(aConstraint)->process(theStorage, theEventsBlocked); if (aConstraint->error().empty()) { aConstraint->startPoint(theFrom); + theStorage->adjustParametrizationOfArcs(); theSketchSolver->initialize(); aConstraint->moveTo(theTo); theStorage->setNeedToResolve(true); @@ -165,18 +197,29 @@ bool SketchSolver_Group::moveFeature(FeaturePtr theFeature, const std::shared_ptr& theFrom, const std::shared_ptr& theTo) { - SolverConstraintPtr aConstraint = - move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, theFeature, theFrom, theTo); + EntityWrapperPtr anEntity = myStorage->entity(theFeature); + SolverConstraintPtr aConstraint = move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, + theFeature, anEntity, theFrom, theTo); setTemporary(aConstraint); return true; } bool SketchSolver_Group::movePoint(AttributePtr theAttribute, + const int thePointIndex, const std::shared_ptr& theFrom, const std::shared_ptr& theTo) { - SolverConstraintPtr aConstraint = - move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, theAttribute, theFrom, theTo); + EntityWrapperPtr anEntity = myStorage->entity(theAttribute); + SolverConstraintPtr aConstraint; + if (thePointIndex < 0) { + aConstraint = move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, + theAttribute, anEntity, theFrom, theTo); + } + else { + aConstraint = move(myStorage, mySketchSolver, myDOF, myIsEventsBlocked, + std::pair(theAttribute, thePointIndex), anEntity, + theFrom, theTo); + } setTemporary(aConstraint); return true; } @@ -208,8 +251,10 @@ bool SketchSolver_Group::resolveConstraints() PlaneGCSSolver_Solver::SolveStatus aResult = PlaneGCSSolver_Solver::STATUS_OK; try { - if (!isGroupEmpty) + if (!isGroupEmpty) { + myStorage->adjustParametrizationOfArcs(); aResult = mySketchSolver->solve(); + } if (aResult == PlaneGCSSolver_Solver::STATUS_FAILED && !myTempConstraints.empty()) { mySketchSolver->undo(); @@ -290,8 +335,9 @@ bool SketchSolver_Group::resolveConstraints() } } - // show degrees of freedom only if the degenerated geometry appears - if (aResult == PlaneGCSSolver_Solver::STATUS_DEGENERATED) + // show degrees of freedom only if the degenerated geometry appears, + // or if DoF is not computed yet + if (aResult == PlaneGCSSolver_Solver::STATUS_DEGENERATED || myDOF < 0) computeDoF(); } @@ -320,15 +366,29 @@ bool SketchSolver_Group::resolveConstraints() // ============================================================================ void SketchSolver_Group::computeDoF() { - std::ostringstream aDoFMsg; + std::string aDoFMsg; + static const std::string aMsgContext("Sketch"); int aDoF = mySketchSolver->dof(); /// "DoF = 0" content of string value is used in PartSet by Sketch edit /// If it is changed, it should be corrected also there - if (aDoF == 0) - aDoFMsg << "Sketch is fully fixed (DoF = 0)"; - else - aDoFMsg << "DoF (degrees of freedom) = " << aDoF; - mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aDoFMsg.str()); + //if (aDoF == 0) { + // static const std::string aMsgDoF("Sketch is fully fixed (DoF = 0)"); + // aDoFMsg = Config_Translator::translate(aMsgContext, aMsgDoF); + //} else { + // static const std::string aMsgDoF("DoF (degrees of freedom) = %1"); + // Events_InfoMessage aMsg(aMsgContext, aMsgDoF); + // aMsg.addParameter(aDoF); + // aDoFMsg = Config_Translator::translate(aMsg); + //} + //// store Unicode value for translated message about DoF + //size_t aLen = aDoFMsg.size(); + //std::wstring aWStr(aLen, L'#'); + //mbstowcs(&aWStr[0], aDoFMsg.c_str(), aLen); + //mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aWStr); + + std::ostringstream aStr; + aStr << aDoF; + mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aStr.str()); if (aDoF > 0 && myDOF <= 0) sendMessage(EVENT_SKETCH_UNDER_CONSTRAINED, mySketch, aDoF); @@ -449,3 +509,8 @@ bool SketchSolver_Group::areConstraintsValid() const return false; return true; } + +void SketchSolver_Group::underconstrainedFeatures(std::set& theFeatures) const +{ + myStorage->getUnderconstrainedGeometry(theFeatures); +}