From: Jérôme Date: Fri, 30 Oct 2020 16:12:19 +0000 (+0100) Subject: Improvement coding style, Documentation, Translation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c33b9669faff5426b669104f6caa3da2786a9db4;p=modules%2Fshaper.git Improvement coding style, Documentation, Translation --- diff --git a/src/BuildAPI/BuildAPI_Interpolation.cpp b/src/BuildAPI/BuildAPI_Interpolation.cpp index f232b81da..353eff358 100644 --- a/src/BuildAPI/BuildAPI_Interpolation.cpp +++ b/src/BuildAPI/BuildAPI_Interpolation.cpp @@ -39,7 +39,7 @@ BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, : ModelHighAPI_Interface(theFeature) { if(initialize()) { - fillAttribute(BuildPlugin_Interpolation::CREATION_METHODE_BY_SELECTION_ID(),mycreationmethod); + fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID(),mycreationmethod); setUseTangents(true); setTangents(theStartTangent, theEndTangent); setClosed(theIsClosed); @@ -49,14 +49,15 @@ BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, } //================================================================================================== -BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, - const std::list& theBaseObjects, - const bool theIsClosed, - const bool theIsToReorder) +BuildAPI_Interpolation::BuildAPI_Interpolation( + const FeaturePtr& theFeature, + const std::list& theBaseObjects, + const bool theIsClosed, + const bool theIsToReorder) : ModelHighAPI_Interface(theFeature) { if (initialize()) { - fillAttribute(BuildPlugin_Interpolation::CREATION_METHODE_BY_SELECTION_ID(),mycreationmethod); + fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID(),mycreationmethod); setClosed(theIsClosed); setReorder(theIsToReorder); setUseTangents(false); @@ -65,16 +66,16 @@ BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, } BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, - const std::string & theXTexpression, - const std::string & theYTexpression, - const std::string & theZTexpression, - const ModelHighAPI_Double& theMinT, - const ModelHighAPI_Double& theMaxT, - const ModelHighAPI_Integer& theNbStep) + const std::string & theXTexpression, + const std::string & theYTexpression, + const std::string & theZTexpression, + const ModelHighAPI_Double& theMinT, + const ModelHighAPI_Double& theMaxT, + const ModelHighAPI_Integer& theNbStep) : ModelHighAPI_Interface(theFeature) { if (initialize()) { - fillAttribute(BuildPlugin_Interpolation::CREATION_METHODE_ANALYTICAL_ID(),mycreationmethod); + fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_ANALYTICAL_ID(),mycreationmethod); fillAttribute(theXTexpression, myxt); fillAttribute(theYTexpression, myyt); fillAttribute(theZTexpression, myzt); @@ -136,8 +137,8 @@ void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const FeaturePtr aBase = feature(); std::string aPartName = theDumper.name(aBase->document()); - if( aBase->string(BuildPlugin_Interpolation::CREATION_METHODE_ID())->value() == - BuildPlugin_Interpolation::CREATION_METHODE_BY_SELECTION_ID() ) + if( aBase->string(BuildPlugin_Interpolation::CREATION_METHOD_ID())->value() == + BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID() ) { AttributeSelectionListPtr anAttrBaseObjects = aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID()); @@ -159,7 +160,7 @@ void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const theDumper << closed() << ", " << reorder() << ")" << std::endl; }else{ - theDumper << aBase << " = model.addInterpolation(" << aPartName ; + theDumper << aBase << " = model.addInterpolation(" << aPartName ; AttributeStringPtr XtAttr = xt(); std::string xt = XtAttr->value(); AttributeStringPtr YtAttr = yt(); diff --git a/src/BuildAPI/BuildAPI_Interpolation.h b/src/BuildAPI/BuildAPI_Interpolation.h index 732a57a90..ebde245b3 100644 --- a/src/BuildAPI/BuildAPI_Interpolation.h +++ b/src/BuildAPI/BuildAPI_Interpolation.h @@ -96,7 +96,7 @@ public: ModelAPI_AttributeDouble, /** zt expression*/, numstep, BuildPlugin_Interpolation::NUMSTEP_ID(), ModelAPI_AttributeInteger, /** zt expression*/, - creationmethod, BuildPlugin_Interpolation::CREATION_METHODE_ID(), + creationmethod, BuildPlugin_Interpolation::CREATION_METHOD_ID(), ModelAPI_AttributeString, /** zt expression*/) /// Modify base attribute of the feature. diff --git a/src/BuildPlugin/BuildPlugin_EvalListener.h b/src/BuildPlugin/BuildPlugin_EvalListener.h index 3951559eb..5ace4821f 100644 --- a/src/BuildPlugin/BuildPlugin_EvalListener.h +++ b/src/BuildPlugin/BuildPlugin_EvalListener.h @@ -27,6 +27,7 @@ class ModelAPI_Attribute; class ModelAPI_Document; class ModelAPI_Feature; class ModelAPI_ResultParameter; + class InitializationPlugin_PyInterp; /** diff --git a/src/BuildPlugin/BuildPlugin_Interpolation.cpp b/src/BuildPlugin/BuildPlugin_Interpolation.cpp index 433a92d02..a515c4552 100644 --- a/src/BuildPlugin/BuildPlugin_Interpolation.cpp +++ b/src/BuildPlugin/BuildPlugin_Interpolation.cpp @@ -72,10 +72,9 @@ void BuildPlugin_Interpolation::initAttributes() data()->addAttribute(TANGENT_START_ID(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(TANGENT_END_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(CREATION_METHODE_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(CREATION_METHODE_BY_SELECTION_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(CREATION_METHODE_ANALYTICAL_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(CREATION_METHODE_ANALYTICAL_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(CREATION_METHOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(CREATION_METHOD_BY_SELECTION_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(CREATION_METHOD_ANALYTICAL_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(EXPRESSION_ERROR_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(VARIABLE_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(VALUE_ID(), ModelAPI_AttributeTables::typeId()); @@ -90,9 +89,9 @@ void BuildPlugin_Interpolation::initAttributes() data()->addAttribute(NUMSTEP_ID(), ModelAPI_AttributeInteger::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), - CREATION_METHODE_ANALYTICAL_ID()); + CREATION_METHOD_ANALYTICAL_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), - CREATION_METHODE_BY_SELECTION_ID()); + CREATION_METHOD_BY_SELECTION_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VARIABLE_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VALUE_ID()); data()->addAttribute(ARGUMENTS_ID(), ModelAPI_AttributeRefList::typeId()); @@ -123,13 +122,13 @@ void BuildPlugin_Interpolation::attributeChanged(const std::string& theID) && string(XT_ID())->value() !="" && string(YT_ID())->value() !="" && string(ZT_ID())->value() !="" - && string(CREATION_METHODE_ID())->value() == CREATION_METHODE_ANALYTICAL_ID() + && string(CREATION_METHOD_ID())->value() == CREATION_METHOD_ANALYTICAL_ID() ){ - updateCoods(); + updateCoordinates(); } } -void BuildPlugin_Interpolation::updateCoods() +void BuildPlugin_Interpolation::updateCoordinates() { std::wstring exp; double aMint = real(MINT_ID())->value(); @@ -140,13 +139,13 @@ void BuildPlugin_Interpolation::updateCoods() setError("The minimum value of the parameter must be less than maximum value !!!" ); } - double scale = (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++ ){ ModelAPI_AttributeTables::Value aVal; - aVal.myDouble = step * scale + aMint; + aVal.myDouble = step * aScale + aMint; tables(VALUE_ID())->setValue(aVal,step,0); } @@ -180,7 +179,7 @@ static GeomDirPtr selectionToDir(const AttributeSelectionPtr& theSelection) //================================================================================================= void BuildPlugin_Interpolation::execute() { - if( string(CREATION_METHODE_ID())->value() == CREATION_METHODE_BY_SELECTION_ID() ) + if( string(CREATION_METHOD_ID())->value() == CREATION_METHOD_BY_SELECTION_ID() ) { // Get closed flag value bool isClosed = boolean(CLOSED_ID())->value(); @@ -250,39 +249,39 @@ void BuildPlugin_Interpolation::execute() return false; if (!outErrorMessage.empty()){ - setError("Error: Python interpreter " ); + setError("Error: Python interpreter " );//+ outErrorMessage); return false; } - AttributeTablesPtr table = tables( VALUE_ID() ); - std::list > aCoodPoints; - for( int step = 0; step < table->rows() ; step++ ){ - std::vector coodPoint; + 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 = table->value(step, 1); - coodPoint.push_back( value.myDouble ); + value = aTable->value(step, 1); + aCoordPoint.push_back( value.myDouble ); //y - value = table->value(step, 2); - coodPoint.push_back( value.myDouble ); - //Z - value = table->value(step, 3); - coodPoint.push_back( value.myDouble ); + value = aTable->value(step, 2); + aCoordPoint.push_back( value.myDouble ); + // + value = aTable->value(step, 3); + aCoordPoint.push_back( value.myDouble ); - aCoodPoints.push_back(coodPoint); + aCoordPoints.push_back(aCoordPoint); } std::list aPoints; std::list aVertices; - std::list >::const_iterator aItCoodPoints = aCoodPoints.begin(); + std::list >::const_iterator anItCoordPoints = aCoordPoints.begin(); - for( ; aItCoodPoints != aCoodPoints.end(); ++aItCoodPoints ){ + for( ; anItCoordPoints != aCoordPoints.end(); ++anItCoordPoints ){ - GeomVertexPtr vertex = - GeomAlgoAPI_PointBuilder::vertex( (*aItCoodPoints)[0], - (*aItCoodPoints)[1], - (*aItCoodPoints)[2]); - aPoints.push_back (vertex->point()); - aVertices.push_back (vertex); + GeomVertexPtr aVertex = + GeomAlgoAPI_PointBuilder::vertex( (*anItCoordPoints)[0], + (*anItCoordPoints)[1], + (*anItCoordPoints)[2]); + aPoints.push_back (aVertex->point()); + aVertices.push_back (aVertex); } // Create curve from points @@ -302,11 +301,8 @@ void BuildPlugin_Interpolation::execute() aResultBody->generated(anExp.current(), aVertexName); aVertexIndex++; } - setResult(aResultBody); - } - } void BuildPlugin_Interpolation::evaluate(std::string& theError) diff --git a/src/BuildPlugin/BuildPlugin_Interpolation.h b/src/BuildPlugin/BuildPlugin_Interpolation.h index e921ae5ac..6697162bb 100644 --- a/src/BuildPlugin/BuildPlugin_Interpolation.h +++ b/src/BuildPlugin/BuildPlugin_Interpolation.h @@ -40,23 +40,23 @@ public: return MY_ID; } /// Attribute name of creation method. - inline static const std::string& CREATION_METHODE_ID() + inline static const std::string& CREATION_METHOD_ID() { - static const std::string MY_CREATION_METHODE_ID("interpolation_method"); - return MY_CREATION_METHODE_ID; + static const std::string MY_CREATION_METHOD_ID("interpolation_method"); + return MY_CREATION_METHOD_ID; } /// Attribute name of creation method by selection - inline static const std::string& CREATION_METHODE_BY_SELECTION_ID() + inline static const std::string& CREATION_METHOD_BY_SELECTION_ID() { - static const std::string MY_CREATION_METHODE_BY_SELECTION_ID("by_selection"); - return MY_CREATION_METHODE_BY_SELECTION_ID; + static const std::string MY_CREATION_METHOD_BY_SELECTION_ID("by_selection"); + return MY_CREATION_METHOD_BY_SELECTION_ID; } /// Attribute name of creation method analytical - inline static const std::string& CREATION_METHODE_ANALYTICAL_ID() + inline static const std::string& CREATION_METHOD_ANALYTICAL_ID() { - static const std::string MY_CREATION_METHODE_ANALYTICAL_ID("analytical"); - return MY_CREATION_METHODE_ANALYTICAL_ID; + static const std::string MY_CREATION_METHOD_ANALYTICAL_ID("analytical"); + return MY_CREATION_METHOD_ANALYTICAL_ID; } /// Attribute name of base objects. @@ -189,12 +189,12 @@ public: BUILDPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); protected: - /// Evaluates theExpression and returns its value. + /// Evaluates the expression x(t), y(t),z(t) in value table. void evaluate(std::string& theError); - void updateCoods(); + //Update coordinates x,y,z + void updateCoordinates(); - std::list aCoodPoints[3]; std::string outErrorMessage; }; diff --git a/src/BuildPlugin/BuildPlugin_msg_fr.ts b/src/BuildPlugin/BuildPlugin_msg_fr.ts index e6c433fbb..9b01bdfdd 100644 --- a/src/BuildPlugin/BuildPlugin_msg_fr.ts +++ b/src/BuildPlugin/BuildPlugin_msg_fr.ts @@ -827,7 +827,29 @@ Tangentes - + + Interpolation:analytical + + Curves parameters + Paramètres de la courbe + + + X(t) equation + Équation X(t) + + + Y(t) equation + Équation Y(t) + + + Z(t) equation + Équation Z(t) + + + Number of steps + Nombre de pas + + Polyline:base_objects diff --git a/src/BuildPlugin/doc/TUI_interpolationFeature.rst b/src/BuildPlugin/doc/TUI_interpolationFeature.rst index cfcaf78bd..900bc9ad4 100644 --- a/src/BuildPlugin/doc/TUI_interpolationFeature.rst +++ b/src/BuildPlugin/doc/TUI_interpolationFeature.rst @@ -10,3 +10,14 @@ Create Interpolation :download:`Download this script ` + .. _tui_create_interpolation_analytical: + +Create Interpolation analytical +=============================== + +.. literalinclude:: examples/interpolationAnalytical.py + :linenos: + :language: python + +:download:`Download this script ` + \ No newline at end of file diff --git a/src/BuildPlugin/doc/examples/interpolationAnalytical.py b/src/BuildPlugin/doc/examples/interpolationAnalytical.py new file mode 100644 index 000000000..f39fe81ed --- /dev/null +++ b/src/BuildPlugin/doc/examples/interpolationAnalytical.py @@ -0,0 +1,9 @@ +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Interpolation_1 = model.addInterpolation(Part_1_doc, "5*sin(t)","5*cos(t)","t*0.2", 0, 25, 100) +model.do() +model.end() diff --git a/src/BuildPlugin/doc/images/CreateInterpolationanalitycal.png b/src/BuildPlugin/doc/images/CreateInterpolationanalitycal.png new file mode 100644 index 000000000..2daa9459b Binary files /dev/null and b/src/BuildPlugin/doc/images/CreateInterpolationanalitycal.png differ diff --git a/src/BuildPlugin/doc/images/Interpolation.png b/src/BuildPlugin/doc/images/Interpolation.png index 14967cf1f..06631c70a 100644 Binary files a/src/BuildPlugin/doc/images/Interpolation.png and b/src/BuildPlugin/doc/images/Interpolation.png differ diff --git a/src/BuildPlugin/doc/images/InterpolationAnalitycal.png b/src/BuildPlugin/doc/images/InterpolationAnalitycal.png new file mode 100644 index 000000000..e56e54f13 Binary files /dev/null and b/src/BuildPlugin/doc/images/InterpolationAnalitycal.png differ diff --git a/src/BuildPlugin/doc/images/InterpolationAnalytical.png b/src/BuildPlugin/doc/images/InterpolationAnalytical.png new file mode 100644 index 000000000..c26a48496 Binary files /dev/null and b/src/BuildPlugin/doc/images/InterpolationAnalytical.png differ diff --git a/src/BuildPlugin/doc/images/feature_interpolation_analytical.png b/src/BuildPlugin/doc/images/feature_interpolation_analytical.png new file mode 100644 index 000000000..a47790fc6 Binary files /dev/null and b/src/BuildPlugin/doc/images/feature_interpolation_analytical.png differ diff --git a/src/BuildPlugin/doc/images/feature_interpolation_by_selection.png b/src/BuildPlugin/doc/images/feature_interpolation_by_selection.png new file mode 100644 index 000000000..e5c5374b9 Binary files /dev/null and b/src/BuildPlugin/doc/images/feature_interpolation_by_selection.png differ diff --git a/src/BuildPlugin/doc/interpolationFeature.rst b/src/BuildPlugin/doc/interpolationFeature.rst index 2da696243..62b600381 100644 --- a/src/BuildPlugin/doc/interpolationFeature.rst +++ b/src/BuildPlugin/doc/interpolationFeature.rst @@ -3,7 +3,7 @@ Interpolation ============= -Interpolation feature creates a curve (edge) using vertices already existing in other objects. +Interpolation feature creates an interpolated curve (edge) based on existing points/vertices or based on analytical mathematical expression. To create an interpolation in the active part: @@ -12,6 +12,29 @@ To create an interpolation in the active part: The following property panel will be opened: +.. figure:: images/Interpolation.png + :align: center + + Create an interpolation + +There are two creation modes of an interpolation: + +.. figure:: images/feature_interpolation_by_selection.png + :align: left + :height: 24px + +Interpolation by selection + +.. figure:: images/feature_interpolation_analytical.png + :align: left + :height: 24px + +interpolation analytical + +Interpolation by selection +"""""""""""""""""""""""""" +The property panel is shown below. + .. figure:: images/Interpolation.png :align: center @@ -60,3 +83,55 @@ The result of the operation will be a curve created from the selected shapes: Result of the operation. **See Also** a sample TUI Script of :ref:`tui_create_interpolation` operation. + +Interpolation analytical +"""""""""""""""""""""""" + +The property panel is shown below. + +.. figure:: images/InterpolationAnalitycal.png + :align: center + + Create an interpolation analytical + +Select one or several vertices or points in the viewer. + +- **Curves parameters** panel allows to define the mathematical expression for creating the interpolated curve. + - **X(t) equation** define the expression of X with t variable. + - **Y(t) equation** define the expression of Y with t variable. + - **Z(t) equation** define the expression of Z with t variable. + +- **Min t** define the minimun of t. + +- **Max t** define the maximum of t. + +- **Number of steps** define the number of steps. + +**Apply** button creates an interpolation. + +**Cancel** button cancels the operation. + +**TUI Commands**: + +.. py:function:: model.addInterpolation(Part_doc, xt, yt, zt, mint, maxt, nbSteps) + + :param part: The current part object. + :param xt: Expression of x. + :param yt: Expression of y. + :param zt: Expression of z. + :param mint: Minimum value of t + :param maxt: Maximum value of t. + :param nbSteps: Number of steps. + :return: Result object. + +Result +"""""" + +The result of the operation will be a curve created from analytical expressions for x,y and z as functions of variable t: + +.. figure:: images/CreateInterpolationanalitycal.png + :align: center + + Result of the operation. + +**See Also** a sample TUI Script of :ref:`tui_create_interpolation_analytical` operation. \ No newline at end of file diff --git a/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp b/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp index 606a78871..1d96ff115 100644 --- a/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp +++ b/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp @@ -42,9 +42,9 @@ bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptrname().substr(0, 6) == L"Interp" ) { AttributeStringPtr anAttr =theFeature->string( - BuildPlugin_Interpolation::CREATION_METHODE_ID()); + BuildPlugin_Interpolation::CREATION_METHOD_ID()); if ( anAttr->isInitialized() ) - if( anAttr->value() == BuildPlugin_Interpolation::CREATION_METHODE_ANALYTICAL_ID()) + if( anAttr->value() == BuildPlugin_Interpolation::CREATION_METHOD_ANALYTICAL_ID()) return true; } diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 11a6aecc9..dffa73a8d 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -365,7 +365,7 @@ class ModelAPI_BuildEvalMessage : public Events_Message /// Static. Returns EventID of the message. MODELAPI_EXPORT static Events_ID& eventId() { - static const char * MY_BUILD_EVALUATION_EVENT_ID("ParameterEvaluationRequest"); + static const char * MY_BUILD_EVALUATION_EVENT_ID("BuildEvaluationRequest"); static Events_ID anId = Events_Loop::eventByName(MY_BUILD_EVALUATION_EVENT_ID); return anId; }