From: vsv Date: Thu, 16 Apr 2015 14:45:37 +0000 (+0300) Subject: Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 X-Git-Tag: V_1.1.0~21^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=653805f5d615b18e3a5a9640a86ae55ba5779d69;hp=6a7e53a3d3b52f1f798b7e3aa3c48de9c870d92b;p=modules%2Fshaper.git Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index e3d7eb34c..ae24aaf3c 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -59,6 +59,19 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() } } +void ConstructionPlugin_Axis::createAxisByCylindricalFace() +{ + std::shared_ptr aSelection = data()->selection(CYLINDRICAL_FACE())->value(); + // update arguments due to the selection value + if (aSelection && !aSelection->isNull() && aSelection->isFace()) { + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setShape(anEdge); + setResult(aConstr); + } +} + void ConstructionPlugin_Axis::execute() { AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); @@ -66,14 +79,12 @@ void ConstructionPlugin_Axis::execute() if (aMethodType == "AxisByPointsCase") { createAxisByTwoPoints(); } else if (aMethodType == "AxisByCylindricalFaceCase") { - #ifdef _DEBUG - std::cout << "ConstructionPlugin_Axis::execute: " << "AxisByCylindricalFaceCase is not supported yet." << std::endl; - #endif + createAxisByCylindricalFace(); } } bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) + std::shared_ptr theDefaultPrs) { bool isCustomized = theDefaultPrs.get() != NULL && theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index df8aedcfd..1775300eb 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -78,6 +78,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP protected: void createAxisByTwoPoints(); + void createAxisByCylindricalFace(); }; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index f1ecb2b34..0de55a60f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -32,6 +34,36 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( return aRes; } +std::shared_ptr GeomAlgoAPI_EdgeBuilder::cylinderAxis( + std::shared_ptr theCylindricalFace) +{ + std::shared_ptr aResult; + const TopoDS_Shape& aShape = theCylindricalFace->impl(); + if (aShape.IsNull()) + return aResult; + TopoDS_Face aFace = TopoDS::Face(aShape); + if (aFace.IsNull()) + return aResult; + TopLoc_Location aLoc; + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc); + if (aSurf.IsNull()) + return aResult; + Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf); + if (aCyl.IsNull()) + return aResult; + gp_Ax1 anAxis = aCyl->Axis(); + gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation())); + // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder + gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.); + anEnd.Transform(aLoc.Transformation()); + + BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); + std::shared_ptr aRes(new GeomAPI_Edge); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} + std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircle( std::shared_ptr theCenter, std::shared_ptr theNormal, double theRadius) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index ef0f82df4..0bd67621b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -23,7 +23,10 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder public: /// Creates linear edge by two points static std::shared_ptr line(std::shared_ptr theStart, - std::shared_ptr theEnd); + std::shared_ptr theEnd); + /// Creates edge - axis of the given cylindrical face + static std::shared_ptr cylinderAxis( + std::shared_ptr theCylindricalFace); /// Creates linear edge in a form of a circle by a point and a circle radius static std::shared_ptr lineCircle(std::shared_ptr theCenter, diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index ec0c236f6..c2321d59b 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1300,6 +1300,9 @@ void Model_Document::updateResults(FeaturePtr theFeature) break; } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) { aNewBody = createGroup(theFeature->data(), aResIndex); + } else if (aGroup->Get() == ModelAPI_ResultParameter::group().c_str()) { + theFeature->attributeChanged("expression"); // just produce a value + break; } else { Events_Error::send(std::string("Unknown type of result is found in the document:") + TCollection_AsciiString(aGroup->Get()).ToCString()); diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 57e21b80b..925b1cc94 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -256,5 +256,7 @@ void ModuleBase_ParamSpinBox::keyPressEvent(QKeyEvent* e) void ModuleBase_ParamSpinBox::showEvent(QShowEvent* theEvent) { ModuleBase_DoubleSpinBox::showEvent(theEvent); - //setText(myTextValue); + if (hasVariable(myTextValue)) { + setText(myTextValue); + } } diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index a17ea26c9..551f9e7c8 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -96,12 +96,11 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() void ModuleBase_WidgetDoubleValue::reset() { - if (isComputedDefault()) { + if (isComputedDefault() || mySpinBox->hasVariable()) { return; //if (myFeature->compute(myAttributeID)) // restoreValue(); - } - else { + } else { bool isOk; double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk); // reset the value just if there is a default value definition in the XML definition @@ -121,6 +120,8 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() const std::string aTextRepr = aReal->text(); if (mySpinBox->hasVariable()) { aTextRepr = mySpinBox->text().toStdString(); + } else { + aTextRepr = ""; } aReal->setText(aTextRepr); updateObject(myFeature); diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp index 70840ccff..48f5d7312 100644 --- a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp @@ -18,6 +18,7 @@ ParametersPlugin_Parameter::ParametersPlugin_Parameter() { myInterp = new ParametersPlugin_PyInterp(); + myInterp->initialize(); } ParametersPlugin_Parameter::~ParametersPlugin_Parameter() @@ -76,7 +77,7 @@ void ParametersPlugin_Parameter::execute() double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError) { - myInterp->initialize(); + std::list anExprParams = myInterp->compile(theExpression); // find expression's params in the model std::list aContext; @@ -92,6 +93,6 @@ double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, st } myInterp->extendLocalContext(aContext); double result = myInterp->evaluate(theExpression, theError); - myInterp->destroy(); + myInterp->clearLocalContext(); return result; } diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp index 7a5f42c4f..4afbfaa2a 100644 --- a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp +++ b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp @@ -69,6 +69,12 @@ void ParametersPlugin_PyInterp::extendLocalContext(const std::list& } } +void ParametersPlugin_PyInterp::clearLocalContext() +{ + PyLockWrapper lck; + PyDict_Clear(_local_context); +} + double ParametersPlugin_PyInterp::evaluate(const std::string& theExpression, std::string& theError) { diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.h b/src/ParametersPlugin/ParametersPlugin_PyInterp.h index 4151f4e23..0e3cdee56 100644 --- a/src/ParametersPlugin/ParametersPlugin_PyInterp.h +++ b/src/ParametersPlugin/ParametersPlugin_PyInterp.h @@ -22,6 +22,7 @@ class PARAMETERSPLUGIN_EXPORT ParametersPlugin_PyInterp : public PyInterp_Interp std::list compile(const std::string&); void extendLocalContext(const std::list&); + void clearLocalContext(); double evaluate(const std::string&, std::string&); protected: diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index a7f8d5b48..e630978ec 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -411,8 +411,18 @@ bool SketchSolver_Group::resolveConstraints() try { if (myStorage->hasDuplicatedConstraint()) aResult = SLVS_RESULT_INCONSISTENT; - else - aResult = myConstrSolver.solve(); + else { + // To avoid overconstraint situation, we will remove temporary constraints one-by-one + // and try to find the case without overconstraint + int aNbTemp = (int)myTempConstraints.size(); + while (true) { + aResult = myConstrSolver.solve(); + if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0) + break; + aNbTemp = myStorage->removeFirstTemporaryConstraint(); + myStorage->initializeSolver(myConstrSolver); + } + } } catch (...) { Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this); return false; diff --git a/src/SketchSolver/SketchSolver_Solver.cpp b/src/SketchSolver/SketchSolver_Solver.cpp index 0e7b1761c..4e7a4f0e9 100644 --- a/src/SketchSolver/SketchSolver_Solver.cpp +++ b/src/SketchSolver/SketchSolver_Solver.cpp @@ -63,8 +63,10 @@ void SketchSolver_Solver::setConstraints(Slvs_Constraint* theConstraints, int th myEquationsSystem.constraints = theSize; } else if (myEquationsSystem.constraints != theSize) { - delete[] myEquationsSystem.constraint; - myEquationsSystem.constraint = new Slvs_Constraint[theSize]; + if (theSize > myEquationsSystem.constraints) { + delete[] myEquationsSystem.constraint; + myEquationsSystem.constraint = new Slvs_Constraint[theSize]; + } myEquationsSystem.constraints = theSize; } memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint)); diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 1d5a8332d..250ce7e56 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -546,6 +546,15 @@ void SketchSolver_Storage::removeTemporaryConstraints() myTemporaryConstraints.clear(); } +int SketchSolver_Storage::removeFirstTemporaryConstraint() +{ + if (myTemporaryConstraints.empty()) + return 0; + removeConstraint(*myTemporaryConstraints.begin()); + myTemporaryConstraints.erase(myTemporaryConstraints.begin()); + return (int)myTemporaryConstraints.size(); +} + bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const { return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end(); diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index fbd9acf64..fc2e46ceb 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -108,6 +108,9 @@ public: void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID); /// \brief Remove all transient constraints void removeTemporaryConstraints(); + /// \brief Remove first temporary constraint + /// \return Number of remaining temporary constraints + int removeFirstTemporaryConstraint(); /// \brief Checks the constraint is temporary bool isTemporary(const Slvs_hConstraint& theConstraintID) const;