Add fixes.
aLoop->registerListener(this, ModelAPI_ParameterEvalMessage::eventId(), NULL, true);
aLoop->registerListener(this, ModelAPI_BuildEvalMessage::eventId(), NULL, true);
aLoop->registerListener(this, ModelAPI_ComputePositionsMessage::eventId(), NULL, true);
- aLoop->registerListener(this, ModelAPI_PathEvalMessage::eventId(), NULL, true);
+ aLoop->registerListener(this, ModelAPI_ImportParametersMessage::eventId(), NULL, true);
myInterp = std::shared_ptr<InitializationPlugin_PyInterp>(new InitializationPlugin_PyInterp());
myInterp->initialize();
}
aMsg->setResults(aParamsList, anError);
}
- else if (theMessage->eventID() == ModelAPI_PathEvalMessage::eventId())
+ else if (theMessage->eventID() == ModelAPI_ImportParametersMessage::eventId())
{
- std::shared_ptr<ModelAPI_PathEvalMessage> aMsg =
- std::dynamic_pointer_cast<ModelAPI_PathEvalMessage>(theMessage);
- std::string aPath = aMsg->parameter();
- myInterp->runString("from salome.shaper import model; doc = model.activeDocument(); model.importParameters(doc, \"" + aPath + "\")");
+ std::shared_ptr<ModelAPI_ImportParametersMessage> aMsg =
+ std::dynamic_pointer_cast<ModelAPI_ImportParametersMessage>(theMessage);
+ std::string anImportScript("from salome.shaper import model;");
+ std::string aDocScript("doc = model.activeDocument();");
+ std::string anParamImpScript("model.importParameters(doc, \"");
+ std::string aPath = aMsg->filename();
+ myInterp->runString(anImportScript + aDocScript + anParamImpScript + aPath + "\")");
}
}
}
/// Creates an empty message
-ModelAPI_PathEvalMessage::ModelAPI_PathEvalMessage(const Events_ID theID, const void* theSender)
+ModelAPI_ImportParametersMessage::ModelAPI_ImportParametersMessage(const Events_ID theID, const void* theSender)
:Events_Message(theID, theSender)
{
}
-ModelAPI_PathEvalMessage::~ModelAPI_PathEvalMessage()
+ModelAPI_ImportParametersMessage::~ModelAPI_ImportParametersMessage()
{
}
-std::string ModelAPI_PathEvalMessage::parameter() const
+std::string ModelAPI_ImportParametersMessage::filename() const
{
- return myParam;
+ return myFilename;
}
-void ModelAPI_PathEvalMessage::setParameter(std::string theParam)
+void ModelAPI_ImportParametersMessage::setFilename(std::string theFilename)
{
- myParam = theParam;
+ myFilename = theFilename;
}
ModelAPI_BuildEvalMessage::ModelAPI_BuildEvalMessage(
MODELAPI_EXPORT const std::string& error() const;
};
-class ModelAPI_PathEvalMessage : public Events_Message
+class ModelAPI_ImportParametersMessage : public Events_Message
{
- std::string myParam; ///< parameters that should be evaluated
+ std::string myFilename; ///< filename where where parameters are stored
std::string myError; ///< error of processing, empty if there is no error
public:
/// Static. Returns EventID of the message.
MODELAPI_EXPORT static Events_ID& eventId()
{
- static const char* MY_PARAMETER_EVALUATION_EVENT_ID("PathEvalMessage");
+ static const char* MY_PARAMETER_EVALUATION_EVENT_ID("ImportParametersMessage");
static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
return anId;
}
/// Useful method that creates and sends the event.
/// Returns the message, processed, with the resulting fields filled.
- MODELAPI_EXPORT static std::shared_ptr<ModelAPI_PathEvalMessage>
+ MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ImportParametersMessage>
send(std::string theParameter, const void* theSender)
{
- std::shared_ptr<ModelAPI_PathEvalMessage> aMessage =
- std::shared_ptr<ModelAPI_PathEvalMessage>(
- new ModelAPI_PathEvalMessage(eventId(), theSender));
- aMessage->setParameter(theParameter);
+ std::shared_ptr<ModelAPI_ImportParametersMessage> aMessage =
+ std::shared_ptr<ModelAPI_ImportParametersMessage>(
+ new ModelAPI_ImportParametersMessage(eventId(), theSender));
+ aMessage->setFilename(theParameter);
Events_Loop::loop()->send(aMessage);
return aMessage;
}
/// Creates an empty message
- MODELAPI_EXPORT ModelAPI_PathEvalMessage(const Events_ID theID, const void* theSender = 0);
+ MODELAPI_EXPORT ModelAPI_ImportParametersMessage(const Events_ID theID, const void* theSender = 0);
/// The virtual destructor
- MODELAPI_EXPORT virtual ~ModelAPI_PathEvalMessage();
+ MODELAPI_EXPORT virtual ~ModelAPI_ImportParametersMessage();
- /// Returns a parameter stored in the message
- MODELAPI_EXPORT std::string parameter() const;
- /// Sets a parameter to the message
- MODELAPI_EXPORT void setParameter(std::string theParam);
+ /// Returns a filename stored in the message
+ MODELAPI_EXPORT std::string filename() const;
+ /// Sets a filename to the message
+ MODELAPI_EXPORT void setFilename(std::string theFilename);
};
class ModelAPI_BuildEvalMessage : public Events_Message
endforeach(tfile ${TEST_NAMES})
install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY})
+ install(DIRECTORY data DESTINATION ${TEST_INSTALL_DIRECTORY})
endif(${HAVE_SALOME})
void ParametersPlugin_WidgetParamsMgr::onImport()
{
- QStringList aPathes = QFileDialog::getOpenFileNames(nullptr, "Select txt file", "", "Text files (*.txt)", nullptr, {QFileDialog::ExistingFiles});
- if (aPathes.empty())
+ std::string aWinText("Select txt file");
+ std::string aFileType("Text files (*.txt);;All files (*.*)");
+ QFlags<QFileDialog::Option> aOption = {QFileDialog::ExistingFile};
+ QString aQPath = QFileDialog::getOpenFileName(nullptr,
+ aWinText.c_str(), "",
+ aFileType.c_str(), nullptr,
+ aOption);
+ if (aQPath.size() == 0)
return;
- for (auto aPathIter = aPathes.begin(); aPathIter != aPathes.end(); ++aPathIter)
- {
- std::string aPath(aPathIter->toStdString());
- std::shared_ptr<ModelAPI_PathEvalMessage> aMessage =
- std::shared_ptr<ModelAPI_PathEvalMessage>(
- new ModelAPI_PathEvalMessage(ModelAPI_PathEvalMessage::eventId()));
- aMessage->setParameter(aPath);
- Events_Loop::loop()->send(aMessage);
- }
+ std::string aPath(aQPath.toStdString());
+ std::shared_ptr<ModelAPI_ImportParametersMessage> aMessage =
+ std::shared_ptr<ModelAPI_ImportParametersMessage>(
+ new ModelAPI_ImportParametersMessage(ModelAPI_ImportParametersMessage::eventId()));
+ aMessage->setFilename(aPath);
+ Events_Loop::loop()->send(aMessage);
+
updateParametersFeatures();
- /*updateFeaturesPart();*/
updateParametersPart();
}
--- /dev/null
+# Copyright (C) 2014-2021 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from salome.shaper import model
+import os
+
+from PyQt5.Qt import QApplication
+
+import salome
+salome.salome_init_without_session()
+salome.salome_init(1)
+if QApplication.instance() is None:
+ app = QApplication([])
+
+data_dir = os.path.join(os.path.dirname(inspect.getfile(lambda: None)), "data")
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+nameFile = "parameters.txt"
+
+aDir = os.path.join(data_dir, nameFile)
+
+aListOfParameters = model.importParameters(Part_1_doc, aDir)
+
+Box_1 = model.addBox(Part_1_doc, "Longueur", "Largeur", "Hauteur")
+
+assert(len(Box_1.feature().error()) == 0)
+assert(len(aListOfParameters) > 0)
+assert(len(aListOfParameters) == 5)
+assert(model.checkPythonDump())
-###
-### SHAPER component
-###
+# Copyright (C) 2014-2021 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
from salome.shaper import model
--- /dev/null
+Longueur 36. # "Longueur de la pièce"
+Largeur 24. # Largeur de la pièce
+Hauteur Longueur*Largeur
+
+Largeur2
+Largeur3 #Comment
+A12 5. * 5.
+# Comment
+Name#Comment
+ # Comm
+Longueur2 36. #\"Comment\" #Comm #Comm
\ No newline at end of file
:language: python
:download:`Download this script <examples/parameter.py>`
-:download:`Download file for script <examples/File.txt>`
+:download:`Download parameters file sample <examples/File.txt>`
-ax 10.0
-bx 15.0
-cx ax+bx
\ No newline at end of file
+Width 10.0 #Width of square
+Height 15.0 # Height of square
+Area Width*Height # Area of square
\ No newline at end of file
+++ /dev/null
-# 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
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-from salome.shaper import model
-import os
-
-model.begin()
-partSet = model.moduleDocument()
-Part_1 = model.addPart(partSet)
-Part_1_doc = Part_1.document()
-
-data_dir = os.path.join(os.path.dirname(sys.argv[0]), "Test_data")
-
-nameFile = "PythonAPI_test_parametres1.txt"
-
-aDir = os.path.join(data_dir, nameFile)
-
-aFile = open(nameFile, 'w', encoding = "utf_8")
-
-aFile.write("Longueur 36. # \"Longueur de la pièce\"\n")
-aFile.write("Largeur 24. # Largeur de la pièce\n")
-aFile.write("Hauteur Longueur*Largeur\n")
-aFile.write("\n")
-aFile.write(" \n")
-aFile.write("Largeur2\n")
-aFile.write("Largeur3 #Comment\n")
-aFile.write("A12 5. * 5.\n")
-aFile.write("# Comment\n")
-aFile.write("Name#Comment\n")
-aFile.write(" # Comm\n")
-aFile.write("Longueur2 36. #\"Comment\" #Comm #Comm\n")
-
-aFile.close()
-
-aListOfParameters = model.importParameters(Part_1_doc, nameFile)
-
-Box_1 = model.addBox(Part_1_doc, "Longueur", "Largeur", "Hauteur")
-
-assert(len(Box_1.feature().error()) == 0)
-assert(len(aListOfParameters) > 0)
-assert(len(aListOfParameters) == 5)
from salome.shaper import model
import codecs
+def changeTab(theLine):
+ aResult = theLine.split("#")[0].replace("\t"," ")
+ aResult += theLine[len(aResult):]
+ return aResult
+
def importParameters(theDocument, theFileName):
aResult = []
for aLine in aFile:
aLine = aLine.rstrip("\n")
+ aLine = changeTab(aLine)
+
aName = ""
aParameter = ""
aComment = ""
- isOK = True
- isComment = False
+
aFirstText = aLine.split(" ")[0]
aName = aFirstText.split("#")[0].strip()
try:
aResult.append(model.addParameter(theDocument, aName, aParameter.strip(), aComment.strip()))
except SyntaxError as anError:
- anError
+ print(anError)
aFile.close()
return aResult