From 490b2aeb4a3a05e2c79f5f1af2038aaff9e05781 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Tue, 8 Dec 2020 11:30:01 +0100 Subject: [PATCH] Fixed issue #20454 --- src/BuildAPI/BuildAPI_Interpolation.cpp | 2 +- src/BuildPlugin/BuildPlugin_Interpolation.cpp | 73 +++++++++++-------- .../InitializationPlugin_EvalListener.cpp | 4 +- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/BuildAPI/BuildAPI_Interpolation.cpp b/src/BuildAPI/BuildAPI_Interpolation.cpp index f651255be..7b2becdcb 100644 --- a/src/BuildAPI/BuildAPI_Interpolation.cpp +++ b/src/BuildAPI/BuildAPI_Interpolation.cpp @@ -137,7 +137,7 @@ void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const std::string aPartName = theDumper.name(aBase->document()); if (aBase->string(BuildPlugin_Interpolation::CREATION_METHOD_ID())->value() == - BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID() ) + BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID()) { AttributeSelectionListPtr anAttrBaseObjects = aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID()); diff --git a/src/BuildPlugin/BuildPlugin_Interpolation.cpp b/src/BuildPlugin/BuildPlugin_Interpolation.cpp index 2397c8331..edcb547dc 100644 --- a/src/BuildPlugin/BuildPlugin_Interpolation.cpp +++ b/src/BuildPlugin/BuildPlugin_Interpolation.cpp @@ -91,10 +91,9 @@ void BuildPlugin_Interpolation::initAttributes() data()->reflist(ARGUMENTS_ID())->setIsArgument(false); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ARGUMENTS_ID()); - if ( string( XT_ID())->value() == "" - && string( YT_ID())->value() == "" - && string( ZT_ID())->value() == "") - { + if (string(XT_ID())->value() == "" + && string(YT_ID())->value() == "" + && string(ZT_ID())->value() == "") { string(XT_ID())->setValue("t"); string(YT_ID())->setValue("t"); string(ZT_ID())->setValue("t"); @@ -102,7 +101,7 @@ void BuildPlugin_Interpolation::initAttributes() real(MAXT_ID())->setValue(100); integer(NUMSTEP_ID())->setValue(10); updateCoordinates(); - } + } } //================================================================================================= @@ -117,7 +116,7 @@ void BuildPlugin_Interpolation::attributeChanged(const std::string& theID) && string(XT_ID())->value() !="" && string(YT_ID())->value() !="" && string(ZT_ID())->value() !="" - && string(CREATION_METHOD_ID())->value() == CREATION_METHOD_ANALYTICAL_ID()){ + && string(CREATION_METHOD_ID())->value() == CREATION_METHOD_ANALYTICAL_ID()) { updateCoordinates(); } } @@ -131,14 +130,14 @@ void BuildPlugin_Interpolation::updateCoordinates() int aNbrStep = integer(NUMSTEP_ID())->value(); if (aMaxt < aMint) { - setError("The minimum value of the parameter must be less than maximum value !!!" ); + setError("The minimum value of the parameter must be less than maximum value !!!"); } - double aScale = (aMaxt - aMint )/aNbrStep; + double aScale = (aMaxt - aMint)/aNbrStep; string(VARIABLE_ID())->setValue("t"); tables(VALUE_ID())->setSize(aNbrStep+1,4); - for (int step = 0; step <= aNbrStep; step++ ){ + for (int step = 0; step <= aNbrStep; step++) { ModelAPI_AttributeTables::Value aVal; aVal.myDouble = step * aScale + aMint; tables(VALUE_ID())->setValue(aVal,step,0); @@ -147,8 +146,8 @@ void BuildPlugin_Interpolation::updateCoordinates() outErrorMessage=""; evaluate(outErrorMessage); data()->string(EXPRESSION_ERROR_ID())->setValue(outErrorMessage); - if (!outErrorMessage.empty()){ - setError("Error: Python interpreter "); //+ outErrorMessage ); + if (!outErrorMessage.empty()) { + setError("Error: Python interpreter "); return; } } @@ -178,8 +177,7 @@ static GeomDirPtr selectionToDir(const AttributeSelectionPtr& theSelection) //================================================================================================= void BuildPlugin_Interpolation::execute() { - if (string(CREATION_METHOD_ID())->value() == CREATION_METHOD_BY_SELECTION_ID()) - { + if (string(CREATION_METHOD_ID())->value() == CREATION_METHOD_BY_SELECTION_ID()) { // Get closed flag value bool isClosed = boolean(CLOSED_ID())->value(); @@ -240,46 +238,57 @@ void BuildPlugin_Interpolation::execute() setResult(aResultBody); } else { - if (string( XT_ID())->value() == "" - ||string( YT_ID())->value() == "" - ||string( ZT_ID())->value() == "" - ||tables(VALUE_ID())->rows()== 0 ) + if (string(XT_ID())->value() == "" + ||string(YT_ID())->value() == "" + ||string(ZT_ID())->value() == "" + ||tables(VALUE_ID())->rows()== 0) return; bool aWasBlocked = data()->blockSendAttributeUpdated(true); updateCoordinates(); data()->blockSendAttributeUpdated(aWasBlocked, false); - AttributeTablesPtr aTable = tables( VALUE_ID() ); - std::list > aCoordPoints; - for (int step = 0; step < aTable->rows(); step++){ + AttributeTablesPtr aTable = tables(VALUE_ID()); + std::list> aCoordPoints; + for (int step = 0; step < aTable->rows(); step++) { std::vector aCoordPoint; ModelAPI_AttributeTables::Value value; //x value = aTable->value(step, 1); - aCoordPoint.push_back( value.myDouble ); + aCoordPoint.push_back(value.myDouble); //y value = aTable->value(step, 2); - aCoordPoint.push_back( value.myDouble ); + aCoordPoint.push_back(value.myDouble); // value = aTable->value(step, 3); - aCoordPoint.push_back( value.myDouble ); + aCoordPoint.push_back(value.myDouble); aCoordPoints.push_back(aCoordPoint); } std::list aPoints; - std::list aVertices; - std::list >::const_iterator anItCoordPoints = aCoordPoints.begin(); + std::list>::const_iterator anItCoordPoints = aCoordPoints.begin(); - for (; anItCoordPoints != aCoordPoints.end(); ++anItCoordPoints){ + for (; anItCoordPoints!=aCoordPoints.end(); ++anItCoordPoints) { GeomVertexPtr aVertex = - GeomAlgoAPI_PointBuilder::vertex( (*anItCoordPoints)[0], - (*anItCoordPoints)[1], - (*anItCoordPoints)[2]); - aPoints.push_back (aVertex->point()); - aVertices.push_back (aVertex); + GeomAlgoAPI_PointBuilder::vertex((*anItCoordPoints)[0], + (*anItCoordPoints)[1], + (*anItCoordPoints)[2]); + aPoints.push_back(aVertex->point()); + } + + // test if some points are identical + std::list::const_iterator anItPoint1 = aPoints.begin(); + std::list::const_iterator anItPoint2; + for(; anItPoint1 != aPoints.end(); ++ anItPoint1) { + anItPoint2 = anItPoint1; + ++anItPoint2; + for(; anItPoint2 != aPoints.end(); ++ anItPoint2) + if ((*anItPoint2)->isEqual(*anItPoint1)) { + setError("Error: Several points are identical"); + return; + } } // Create curve from points @@ -318,7 +327,7 @@ void BuildPlugin_Interpolation::evaluate(std::string& theError) AttributeRefListPtr aParams = reflist(ARGUMENTS_ID()); aParams->clear(); std::list::const_iterator aNewIter = aParamsList.begin(); - for(; aNewIter != aParamsList.end(); aNewIter++) { + for (; aNewIter != aParamsList.end(); aNewIter++) { aParams->append(*aNewIter); } } else { // error: python interpreter is not active diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index 56193ea49..d6ba3c0d1 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -209,7 +209,7 @@ double InitializationPlugin_EvalListener::evaluate( if (theIsFirstTime) { std::list::iterator anIter = - std::find(theParamsList.begin(),theParamsList.end(), aParamRes ); + std::find(theParamsList.begin(),theParamsList.end(), aParamRes); if (anIter == theParamsList.end()) theParamsList.push_back(aParamRes); } @@ -232,7 +232,7 @@ double InitializationPlugin_EvalListener::evaluate(FeaturePtr theParameter, // find expression's params in the model std::list aContext; std::list::iterator it = anExprParams.begin(); - for ( ; it != anExprParams.end(); it++) { + for (; it != anExprParams.end(); it++) { double aValue; ResultParameterPtr aParamRes; // If variable does not exist python interpreter will generate an error. It is OK. -- 2.39.2