: ModelHighAPI_Interface(theFeature)
{
if(initialize()) {
+ fillAttribute(BuildPlugin_Interpolation::CREATION_METHODE_BY_SELECTION_ID(),mycreationmethod);
setUseTangents(true);
setTangents(theStartTangent, theEndTangent);
setClosed(theIsClosed);
: ModelHighAPI_Interface(theFeature)
{
if (initialize()) {
+ fillAttribute(BuildPlugin_Interpolation::CREATION_METHODE_BY_SELECTION_ID(),mycreationmethod);
setClosed(theIsClosed);
setReorder(theIsToReorder);
setUseTangents(false);
}
}
+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)
+: ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ fillAttribute(BuildPlugin_Interpolation::CREATION_METHODE_ANALYTICAL_ID(),mycreationmethod);
+ fillAttribute(theXTexpression, myxt);
+ fillAttribute(theYTexpression, myyt);
+ fillAttribute(theZTexpression, myzt);
+ fillAttribute(theMinT, mymint);
+ fillAttribute(theMaxT, mymaxt);
+ fillAttribute(theNbStep, mynumstep);
+
+ execute();
+ }
+}
+
//==================================================================================================
BuildAPI_Interpolation::~BuildAPI_Interpolation()
{
FeaturePtr aBase = feature();
std::string aPartName = theDumper.name(aBase->document());
- AttributeSelectionListPtr anAttrBaseObjects =
- aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID());
-
- theDumper << aBase << " = model.addInterpolation(" << aPartName << ", "
- << anAttrBaseObjects << ", ";
-
- AttributeStringPtr useTangentsAttr = useTangents();
- std::string useTangents = useTangentsAttr->value();
- if (!useTangents.empty()) {
- AttributeSelectionPtr anAttrStartTangent =
- aBase->selection(BuildPlugin_Interpolation::TANGENT_START_ID());
- AttributeSelectionPtr anAttrEndTangent =
- aBase->selection(BuildPlugin_Interpolation::TANGENT_END_ID());
-
- theDumper << anAttrStartTangent << ", " << anAttrEndTangent << ", ";
+ if( aBase->string(BuildPlugin_Interpolation::CREATION_METHODE_ID())->value() ==
+ BuildPlugin_Interpolation::CREATION_METHODE_BY_SELECTION_ID() )
+ {
+ AttributeSelectionListPtr anAttrBaseObjects =
+ aBase->selectionList(BuildPlugin_Interpolation::BASE_OBJECTS_ID());
+
+ theDumper << aBase << " = model.addInterpolation(" << aPartName << ", "
+ << anAttrBaseObjects << ", ";
+
+ AttributeStringPtr useTangentsAttr = useTangents();
+ std::string useTangents = useTangentsAttr->value();
+ if (!useTangents.empty()) {
+ AttributeSelectionPtr anAttrStartTangent =
+ aBase->selection(BuildPlugin_Interpolation::TANGENT_START_ID());
+ AttributeSelectionPtr anAttrEndTangent =
+ aBase->selection(BuildPlugin_Interpolation::TANGENT_END_ID());
+
+ theDumper << anAttrStartTangent << ", " << anAttrEndTangent << ", ";
+ }
+
+ theDumper << closed() << ", " << reorder() << ")" << std::endl;
+ }else{
+
+ theDumper << aBase << " = model.addInterpolation(" << aPartName ;
+ AttributeStringPtr XtAttr = xt();
+ std::string xt = XtAttr->value();
+ AttributeStringPtr YtAttr = yt();
+ std::string yt = YtAttr->value();
+ AttributeStringPtr ZtAttr = zt();
+ std::string zt = ZtAttr->value();
+ AttributeDoublePtr minTAttr = mint();
+ double mint = minTAttr->value();
+ AttributeDoublePtr maxTAttr = maxt();
+ double maxt = maxTAttr->value();
+ AttributeIntegerPtr nbStepAttr = numstep();
+ int nbStep = nbStepAttr->value();
+
+ theDumper<< ", \"" << xt << "\",\"" << yt << "\",\""<< zt<< "\", " ;
+ theDumper << mint << ", " << maxt << ", "<< nbStep<< ")"<<std::endl;
}
-
- theDumper << closed() << ", " << reorder() << ")" << std::endl;
}
//==================================================================================================
theIsToReorder));
}
+InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::string & theXTexpression,
+ const std::string & theYTexpression,
+ const std::string & theZTexpression,
+ const ModelHighAPI_Double& theMinT,
+ const ModelHighAPI_Double& theMaxT,
+ const ModelHighAPI_Integer& theNbStep)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(BuildAPI_Interpolation::ID());
+ return InterpolationPtr(new BuildAPI_Interpolation(aFeature,
+ theXTexpression,
+ theYTexpression,
+ theZTexpression,
+ theMinT,
+ theMaxT,
+ theNbStep));
+}
//==================================================================================================
void BuildAPI_Interpolation::execIfBaseNotEmpty()
{
#include <ModelHighAPI_Interface.h>
#include <ModelHighAPI_Macro.h>
#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Integer.h>
+
class ModelHighAPI_Selection;
const std::list<ModelHighAPI_Selection>& theBaseObjects,
const bool theIsClosed, const bool theIsToReorder);
+ /// Constructor with expression analytical of X,Y andZ
+ BUILDAPI_EXPORT
+ explicit 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);
+
/// Destructor.
BUILDAPI_EXPORT
virtual ~BuildAPI_Interpolation();
- INTERFACE_6(BuildPlugin_Interpolation::ID(),
+ INTERFACE_13(BuildPlugin_Interpolation::ID(),
baseObjects, BuildPlugin_Interpolation::BASE_OBJECTS_ID(),
ModelAPI_AttributeSelectionList, /** Base objects */,
closed, BuildPlugin_Interpolation::CLOSED_ID(),
startTangent, BuildPlugin_Interpolation::TANGENT_START_ID(),
ModelAPI_AttributeSelection, /** Start point tangent */,
endTangent, BuildPlugin_Interpolation::TANGENT_END_ID(),
- ModelAPI_AttributeSelection, /** End point tangent */)
+ ModelAPI_AttributeSelection, /** End point tangent */,
+ xt, BuildPlugin_Interpolation::XT_ID(),
+ ModelAPI_AttributeString, /** xt expression*/,
+ yt, BuildPlugin_Interpolation::YT_ID(),
+ ModelAPI_AttributeString, /** yt expression*/,
+ zt, BuildPlugin_Interpolation::ZT_ID(),
+ ModelAPI_AttributeString, /** zt expression*/,
+ mint, BuildPlugin_Interpolation::MINT_ID(),
+ ModelAPI_AttributeDouble, /** zt expression*/,
+ maxt, BuildPlugin_Interpolation::MAXT_ID(),
+ ModelAPI_AttributeDouble, /** zt expression*/,
+ numstep, BuildPlugin_Interpolation::NUMSTEP_ID(),
+ ModelAPI_AttributeInteger, /** zt expression*/,
+ creationmethod, BuildPlugin_Interpolation::CREATION_METHODE_ID(),
+ ModelAPI_AttributeString, /** zt expression*/)
/// Modify base attribute of the feature.
BUILDAPI_EXPORT
const bool theIsClosed = false,
const bool theIsToReorder = false);
+/// \ingroup CPPHighAPI
+/// \brief Create Interpolation feature using tangents.
+BUILDAPI_EXPORT
+InterpolationPtr addInterpolation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::string & theXTexpression,
+ const std::string & theYTexpression,
+ const std::string & theZTexpression,
+ const ModelHighAPI_Double& theMinT,
+ const ModelHighAPI_Double& theMaxT,
+ const ModelHighAPI_Integer& theNbStep);
+
#endif // BuildAPI_Interpolation_H_
AttributeTablesPtr anValueAttr = aParam->tables(BuildPlugin_Interpolation::VALUE_ID());
std::string anError;
std::list<std::shared_ptr<ModelAPI_ResultParameter> > aParamsList;
-
- AttributeStringPtr anExprAttr;
+
+ AttributeStringPtr anExprAttr;
ModelAPI_AttributeTables::Value aVal;
for(int step =0; step < anValueAttr->rows(); step++ ){
anExprAttr = aParam->string(BuildPlugin_Interpolation::XT_ID());
std::wstring anExp = anExprAttr->isUValue() ?
Locale::Convert::toWString(anExprAttr->valueU()) :
Locale::Convert::toWString(anExprAttr->value());
- aVal.myDouble = evaluate(anVar,anValueAttr->value(step,0).myDouble,aParam, anExp, anError, aParamsList, true);
- anValueAttr->setValue(aVal,step,1);
-
+ aVal.myDouble = evaluate(anVar,anValueAttr->value(step,0).myDouble,
+ aParam,
+ anExp,
+ anError,aParamsList,
+ true);
+ anValueAttr->setValue(aVal,step,1);
+
anExprAttr = aParam->string(BuildPlugin_Interpolation::YT_ID());
anExp = anExprAttr->isUValue() ?
Locale::Convert::toWString(anExprAttr->valueU()) :
Locale::Convert::toWString(anExprAttr->value());
- aVal.myDouble = evaluate(anVar,anValueAttr->value(step,0).myDouble,aParam, anExp, anError, aParamsList, true);
+ aVal.myDouble = evaluate(anVar,
+ anValueAttr->value(step,0).myDouble,
+ aParam,
+ anExp,
+ anError,
+ aParamsList,
+ true);
anValueAttr->setValue(aVal,step,2);
anExprAttr = aParam->string(BuildPlugin_Interpolation::ZT_ID());
anExp = anExprAttr->isUValue() ?
Locale::Convert::toWString(anExprAttr->valueU()) :
Locale::Convert::toWString(anExprAttr->value());
- aVal.myDouble = evaluate(anVar,anValueAttr->value(step,0).myDouble,aParam, anExp, anError, aParamsList, true);
+ aVal.myDouble = evaluate(anVar,
+ anValueAttr->value(step,0).myDouble,
+ aParam,
+ anExp,
+ anError,
+ aParamsList,
+ true);
anValueAttr->setValue(aVal,step,3);
}
}
double BuildPlugin_EvalListener::evaluate(
- std::wstring& theVariable,
+ std::wstring& theVariable,
double theValueVariable,
FeaturePtr theParameter,
- const std::wstring& theExpression,
+ const std::wstring& theExpression,
std::string& theError,
std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
const bool theIsParameter)
class ModelAPI_Document;
class ModelAPI_Feature;
class ModelAPI_ResultParameter;
-// JL_CGLB n'existe pas class InitializationPlugin_Parameter;
class BuildPlugin_PyInterp;
/**
protected:
/// Evaluates theExpression and returns its value.
- double evaluate(std::wstring& theVariable,
+ double evaluate(std::wstring& theVariable,
double theValueVariable,std::shared_ptr<ModelAPI_Feature> theParameter,
const std::wstring& theExpression, std::string& theError,
std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
//=================================================================================================
BuildPlugin_Interpolation::BuildPlugin_Interpolation()
{
-
+
}
//=================================================================================================
data()->addAttribute(MINT_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(MAXT_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(NUMSTEP_ID(), ModelAPI_AttributeInteger::typeId());
-
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATION_METHODE_ANALYTICAL_ID());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATION_METHODE_BY_SELECTION_ID());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ CREATION_METHODE_ANALYTICAL_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ CREATION_METHODE_BY_SELECTION_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXPRESSION_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VARIABLE_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VALUE_ID());
-
data()->addAttribute(ARGUMENTS_ID(), ModelAPI_AttributeRefList::typeId());
data()->reflist(ARGUMENTS_ID())->setIsArgument(false);
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ARGUMENTS_ID());
+ string(XT_ID())->setValue("t");
+ string(YT_ID())->setValue("t");
+ string(ZT_ID())->setValue("t");
+ real(MINT_ID())->setValue(0);
+ real(MAXT_ID())->setValue(100);
+ integer(NUMSTEP_ID())->setValue(10);
+ updateCoods();
}
void BuildPlugin_Interpolation::attributeChanged(const std::string& theID)
-{
- if( (theID == XT_ID()
- || theID == YT_ID()
- || theID == ZT_ID()
+{
+ if( (theID == XT_ID()
+ || theID == YT_ID()
+ || theID == ZT_ID()
|| theID == MINT_ID()
|| theID == MAXT_ID()
|| theID == NUMSTEP_ID())
&& string(XT_ID())->value() !=""
&& string(YT_ID())->value() !=""
&& string(ZT_ID())->value() !=""
+ && string(CREATION_METHODE_ID())->value() == CREATION_METHODE_ANALYTICAL_ID()
){
updateCoods();
}
-
}
void BuildPlugin_Interpolation::updateCoods()
-{
+{
std::wstring exp;
- double aMint = real(MINT_ID())->value();
+ double aMint = real(MINT_ID())->value();
double aMaxt = real(MAXT_ID())->value();
- int aNbrStep = integer(NUMSTEP_ID())->value();
- double scale = (aMaxt - aMint )/aNbrStep;
+ int aNbrStep = integer(NUMSTEP_ID())->value();
+ double scale = (aMaxt - aMint )/aNbrStep;
string(VARIABLE_ID())->setValue("t");
tables(VALUE_ID())->setSize(aNbrStep,4);
for( int step = 0; step < aNbrStep; step++ ){
ModelAPI_AttributeTables::Value aVal;
aVal.myDouble = step * scale + aMint;
- tables(VALUE_ID())->setValue(aVal,step,0);
+ tables(VALUE_ID())->setValue(aVal,step,0);
}
outErrorMessage="";
-
+
evaluate(outErrorMessage);
- if (!outErrorMessage.empty()){
- std::cout << L"outErrorMessage= " << outErrorMessage << std::endl;
- }
}
//=================================================================================================
{
if( string( XT_ID())->value() == ""
||string( YT_ID())->value() == ""
- ||string( ZT_ID())->value() == "")
- return;
-
+ ||string( ZT_ID())->value() == ""
+ ||tables(VALUE_ID())->rows()== 0 )
+ return;
+
if (!outErrorMessage.empty()){
setError("Error: Python interpreter " + outErrorMessage);
return;
}
- AttributeTablesPtr table = tables( VALUE_ID() );
+ AttributeTablesPtr table = tables( VALUE_ID() );
std::list<std::vector<double> > aCoodPoints;
for( int step = 0; step < table->rows() ; step++ ){
- std::vector<double> coodPoint;
+ std::vector<double> coodPoint;
ModelAPI_AttributeTables::Value value;
//x
- value = table->value(step, 1);
- coodPoint.push_back( value.myDouble );
+ value = table->value(step, 1);
+ coodPoint.push_back( value.myDouble );
//y
- value = table->value(step, 2);
- coodPoint.push_back( value.myDouble );
+ value = table->value(step, 2);
+ coodPoint.push_back( value.myDouble );
//
- value = table->value(step, 3);
- coodPoint.push_back( value.myDouble );
+ value = table->value(step, 3);
+ coodPoint.push_back( value.myDouble );
aCoodPoints.push_back(coodPoint);
}
-
+
std::list<GeomPointPtr> aPoints;
std::list<GeomVertexPtr> aVertices;
std::list<std::vector<double> >::const_iterator aItCoodPoints = aCoodPoints.begin();
-
+
for( ; aItCoodPoints != aCoodPoints.end(); ++aItCoodPoints ){
- std::cout << "cood = " << "(" << (*aItCoodPoints)[0] << ", "<<
- (*aItCoodPoints)[1] << ", "<<
- (*aItCoodPoints)[2] << " ) "<< std::endl;
- GeomVertexPtr vertex =
+
+ GeomVertexPtr vertex =
GeomAlgoAPI_PointBuilder::vertex( (*aItCoodPoints)[0],
(*aItCoodPoints)[1],
(*aItCoodPoints)[2]);
- aPoints.push_back (vertex->point());
+ aPoints.push_back (vertex->point());
aVertices.push_back (vertex);
- }
- /*
- GeomDirPtr aDirStart(new GeomAPI_Dir( aCoodPoints.front()[0],
- aCoodPoints.front()[1],
- aCoodPoints.front()[2]));
- GeomDirPtr aDirEnd(new GeomAPI_Dir( aCoodPoints.back()[0],
- aCoodPoints.back()[1],
- aCoodPoints.back()[2]));*/
+ }
+
// Create curve from points
GeomEdgePtr anEdge =
- GeomAlgoAPI_CurveBuilder::edge(aPoints, false, true,GeomDirPtr(),GeomDirPtr()); //aDirStart, aDirEnd);
+ GeomAlgoAPI_CurveBuilder::edge(aPoints, false, true,GeomDirPtr(),GeomDirPtr());
if (!anEdge.get()) {
setError("Error: Result curve is empty.");
return;
}
-
+
ResultBodyPtr aResultBody = document()->createBody(data());
// Load the result
aResultBody->store(anEdge);
aResultBody->generated(anExp.current(), aVertexName);
aVertexIndex++;
}
-
+
setResult(aResultBody);
-
+
}
}
if (aProcessMessage->isProcessed()) {
theError = aProcessMessage->error();
- std::cout << "theError= " << theError << std::endl;
} else { // error: python interpreter is not active
theError = "Python interpreter is not available";
}
static const std::string MY_VALUE_ID("value");
return MY_VALUE_ID;
}
-
+
/// attribute of parameter expression
inline static const std::string& EXPRESSION_ID()
{
/// Creates a new part document if needed.
BUILDPLUGIN_EXPORT virtual void execute();
-
+
BUILDPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
protected:
new BuildPlugin_ValidatorBaseForVertex());
aFactory->registerValidator("BuildPlugin_ValidatorExpressionInterpolation",
new BuildPlugin_ValidatorExpressionInterpolation());
-
+
// Register this plugin.
ModelAPI_Session::get()->registerPlugin(this);
model.end()
# =============================================================================
-# Test 12. Check Python dump
+# Test 12. Create curve using an analytical expression
+# =============================================================================
+Part_5 = model.addPart(partSet)
+Part_5_doc = Part_5.document()
+
+Interpolation_11 = model.addInterpolation(Part_5_doc, "sin(t)","cos(t)","t", 0, 100, 10)
+
+model.checkResult(Interpolation_11, model, 1, [0], [0], [0], [1], [2])
+
+# =============================================================================
+# Test 13. Check Python dump
# =============================================================================
assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING))
</shape_selector>
</optionalbox>
</optionalbox>
- <!--JL_CGLB validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/-->
+ <validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/>
</box>
<box id="analytical"
title="Curve analytical"
tooltip="???"
icon="icons/Build/feature_interpolation_analytical.png">
- <stringvalue id="xt" label="X(t) equation" >
+ <groupbox title="Curves parameters">
+ <stringvalue id="xt" label="X(t) equation" >
+ <validator id="BuildPlugin_ValidatorExpressionInterpolation"/>
+ </stringvalue>
+ <stringvalue id="yt" label="Y(t) equation" >
<validator id="BuildPlugin_ValidatorExpressionInterpolation"/>
</stringvalue>
- <stringvalue id="yt" label="Y(t) equation" >
- <validator id="BuildPlugin_ValidatorExpressionInterpolation"/>
- </stringvalue>
- <stringvalue id="zt" label="Z(t) equation" >
- <validator id="BuildPlugin_ValidatorExpressionInterpolation"/>
- </stringvalue>
- <doublevalue id="mint"
- label="Min t"
- min="0"
- default="0">
- <!--validator id="GeomValidators_Positive"/-->
- </doublevalue>
- <doublevalue id="maxt"
- label="Max t"
- min="0"
- default="100">
- <!--validator id="GeomValidators_Positive"/-->
- </doublevalue>
- <integervalue id="numstep"
- label="Number of steps"
- tooltip="Fillet radius."
- min="0"
- default="10">
- <validator id="GeomValidators_Positive"/>
- </integervalue>
+ <stringvalue id="zt" label="Z(t) equation" >
+ <validator id="BuildPlugin_ValidatorExpressionInterpolation"/>
+ </stringvalue>
+ <doublevalue id="mint"
+ label="Min t"
+ min="0"
+ default="0">
+ <!--validator id="GeomValidators_Positive"/-->
+ </doublevalue>
+ <doublevalue id="maxt"
+ label="Max t"
+ min="0"
+ default="100">
+ <!--validator id="GeomValidators_Positive"/-->
+ </doublevalue>
+ <integervalue id="numstep"
+ label="Number of steps"
+ tooltip="Fillet radius."
+ min="0"
+ default="10">
+ <validator id="GeomValidators_Positive"/>
+ </integervalue>
+ </groupbox>
</box>
</toolbox>
</source>
std::shared_ptr<Events_MessageGroup> aStored =
std::dynamic_pointer_cast<Events_MessageGroup>(aMyGroup->second);
aStored->Join(aGroup);
- //std::cout<<"Add to group "<<theMessage->eventID().eventText()<<std::endl;
return;
}
}
${PROJECT_SOURCE_DIR}/src/Events
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+ ${PROJECT_SOURCE_DIR}/src/BuildPlugin
)
INSTALL(TARGETS GeomValidators DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES})
#include <GeomValidators_MinObjectsSelected.h>
#include <Events_InfoMessage.h>
+#include <BuildPlugin_Interpolation.h>
#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeSelectionList.h>
//=================================================================================================
return false;
// LCOV_EXCL_STOP
}
+ //"Interpolation"
+ if( theFeature->name().substr(0, 6) == L"Interp" )
+ {
+ AttributeStringPtr anAttr =theFeature->string(
+ BuildPlugin_Interpolation::CREATION_METHODE_ID());
+ if ( anAttr->isInitialized() )
+ if( anAttr->value() == BuildPlugin_Interpolation::CREATION_METHODE_ANALYTICAL_ID())
+ return true;
+ }
std::string aSelectionListId = theArguments.front();
AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(aSelectionListId);