ModelGeomAlgo
Locale
test_API
+ OperaPlugin
)
//
#include "OperaAPI_Volume.h"
-
-
#include <ModelHighAPI_Dumper.h>
-#include <ModelHighAPI_Double.h>
#include <ModelHighAPI_Tools.h>
-#include <locale> // std::wstring_convert
-#include <codecvt> // std::codecvt_utf8
-
//==================================================================================================
OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr<ModelAPI_Feature>& theFeature)
: ModelHighAPI_Interface(theFeature)
//==================================================================================================
OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const ModelHighAPI_Double& theMedium,
- const std::list<ModelHighAPI_Selection>& theObjectList)
+ const std::string& theMedium,
+ const std::list<ModelHighAPI_Selection>& theObjectsList)
: ModelHighAPI_Interface(theFeature)
{
if(initialize()) {
-
- std::wstring w_medium = theMedium.string();
- std::wstring_convert<std::codecvt_utf8<wchar_t>,wchar_t> cv;
- std::string medium_str = cv.to_bytes(w_medium);
-
- fillAttribute(medium_str, medium());
- setObjectList(theObjectList);
+ fillAttribute(theMedium, medium());
+ setObjectsList(theObjectsList);
}
}
//==================================================================================================
-OperaAPI_Volume::~OperaAPI_Volume() {}
+OperaAPI_Volume::~OperaAPI_Volume()
+{
+}
//==================================================================================================
-void OperaAPI_Volume::setMedium(const ModelHighAPI_Double& theMedium)
+void OperaAPI_Volume::setMedium(const std::string& theMedium)
{
- fillAttribute(OperaPlugin_Volume::MEDIUM_ID(), medium());
+ fillAttribute(theMedium, medium());
execute();
}
//==================================================================================================
-void OperaAPI_Volume::setObjectList(const std::list<ModelHighAPI_Selection>& theObjectList)
+void OperaAPI_Volume::setObjectsList(const std::list<ModelHighAPI_Selection>& theObjectsList)
{
- fillAttribute(theObjectList, volumeList());
+ fillAttribute(theObjectsList, objectsList());
execute();
}
AttributeStringPtr anAttrMedium = aBase->string(OperaPlugin_Volume::MEDIUM_ID());
theDumper << aBase << " = model.addVolume(" << aDocName << ", " << anAttrMedium << ", ";
- AttributeSelectionListPtr anAttrList = aBase->selectionList(OperaPlugin_Volume::VOLUME_LIST_ID());
+ AttributeSelectionListPtr anAttrList =
+ aBase->selectionList(OperaPlugin_Volume::OBJECTS_LIST_ID());
theDumper << anAttrList << ")" << std::endl;
}
//==================================================================================================
VolumePtr addVolume(const std::shared_ptr<ModelAPI_Document>& thePart,
- const ModelHighAPI_Double& theMedium,
- const std::list<ModelHighAPI_Selection>& theObjectList)
+ const std::string& theMedium,
+ const std::list<ModelHighAPI_Selection>& theObjectsList)
{
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(OperaAPI_Volume::ID());
- //aFeature->selectionList(OperaPlugin_Volume::VOLUME_LIST_ID())->setGeometricalSelection(true);
- return VolumePtr(new OperaAPI_Volume(aFeature, theMedium, theObjectList));
+ return VolumePtr(new OperaAPI_Volume(aFeature, theMedium, theObjectsList));
}
#include <ModelHighAPI_Interface.h>
#include <ModelHighAPI_Macro.h>
-class ModelHighAPI_Double;
class ModelHighAPI_Selection;
/// \class OperaAPI_Volume
/// \ingroup CPPHighAPI
-/// \brief Interface for primitive Box feature.
+/// \brief Interface for Volume feature.
class OperaAPI_Volume: public ModelHighAPI_Interface
{
public:
/// Constructor with values.
OPERAAPI_EXPORT
explicit OperaAPI_Volume(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const ModelHighAPI_Double& theMedium,
- const std::list<ModelHighAPI_Selection>& theObjectList);
+ const std::string& theMedium,
+ const std::list<ModelHighAPI_Selection>& theObjectList);
/// Destructor.
OPERAAPI_EXPORT
INTERFACE_2(OperaPlugin_Volume::ID(),
medium, OperaPlugin_Volume::MEDIUM_ID(),
- ModelAPI_AttributeString, /** Volume medium */,
- volumeList, OperaPlugin_Volume::VOLUME_LIST_ID(),
- ModelAPI_AttributeSelectionList, /** Group list*/)
+ ModelAPI_AttributeString, /** Medium */,
+ objectsList, OperaPlugin_Volume::OBJECTS_LIST_ID(),
+ ModelAPI_AttributeSelectionList, /** Objects list*/)
/// Set medium
OPERAAPI_EXPORT
- void setMedium(const ModelHighAPI_Double& theMedium);
+ void setMedium(const std::string& theMedium);
/// Set main objects list.
OPERAAPI_EXPORT
- void setObjectList(const std::list<ModelHighAPI_Selection>& theObjectList);
+ void setObjectsList(const std::list<ModelHighAPI_Selection>& theObjectsList);
/// Dump wrapped feature
OPERAAPI_EXPORT
/// \brief Create Volume feature.
OPERAAPI_EXPORT
VolumePtr addVolume(const std::shared_ptr<ModelAPI_Document>& thePart,
- const ModelHighAPI_Double& theMedium,
- const std::list<ModelHighAPI_Selection>& theObjectList);
+ const std::string& theMedium,
+ const std::list<ModelHighAPI_Selection>& theObjectsList);
-#endif // OperaAPI_Volume_H_
+#endif // OPERAAPI_VOLUME_H_
#include <ModelAPI_Session.h>
#include <string>
-#include <memory>
-#include <iostream>
// the only created instance of this plugin
static OperaPlugin_Plugin* MY_PRIMITIVES_INSTANCE = new OperaPlugin_Plugin();
//
#include <OperaPlugin_Volume.h>
-#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
-#include <GeomAlgoAPI_Copy.h>
-#include <GeomAlgoAPI_Tools.h>
-
#include <sstream>
#include <memory>
-#include <iostream>
//=================================================================================================
OperaPlugin_Volume::OperaPlugin_Volume() // Nothing to do during instantiation
data()->addAttribute(MEDIUM_ID(), ModelAPI_AttributeString::typeId());
// Get Objects
- data()->addAttribute(VOLUME_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+ data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
}
//=================================================================================================
int aResultIndex = 0;
- AttributeSelectionListPtr aList = selectionList(VOLUME_LIST_ID());
+ AttributeSelectionListPtr aList = selectionList(OBJECTS_LIST_ID());
std::wstring aBaseName;
for (int aSelIndex = 0; aSelIndex < aList->size(); aSelIndex++) {
AttributeSelectionPtr aSel = aList->value(aSelIndex);
std::set<std::wstring> anExistingNames;
std::wstring aBaseName = aSel->context() ? aSel->context()->data()->name() :
aSel->contextFeature()->firstResult()->data()->name();
- int anInd = 0;
do {
- anInd++;
std::wostringstream aNameStr;
aNameStr << "Volume_" << aBaseName;
aName = aNameStr.str();
#include <OperaPlugin.h>
#include <ModelAPI_Feature.h>
-#include <GeomAlgoAPI_Box.h>
class GeomAPI_Shape;
class ModelAPI_ResultBody;
return MY_MEDIUM_ID;
}
/// attribute name of selected entities list
- inline static const std::string& VOLUME_LIST_ID()
+ inline static const std::string& OBJECTS_LIST_ID()
{
- static const std::string MY_VOLUME_LIST_ID("volume_list");
- return MY_VOLUME_LIST_ID;
+ static const std::string MY_OBJECTS_LIST_ID("objects_list");
+ return MY_OBJECTS_LIST_ID;
}
// Creates a new part document if needed
<!DOCTYPE TS>
<TS version="2.0" language="fr_FR">
- <context>
- <name>workshop</name>
- <message>
- <source>Volume</source>
- <translation>Volume</translation>
- </message>
- </context>
+ <context>
+ <name>workshop</name>
+ <message>
+ <source>Volume</source>
+ <translation>Volume</translation>
+ </message>
+ </context>
- <context>
- <name>Volume</name>
- <message>
- <source>Volume</source>
- <translation>Volume</translation>
- </message>
- <message>
- <source>Create a volume</source>
- <translation>Créer un volume</translation>
- </message>
- </context>
+ <context>
+ <name>Volume</name>
+ <message>
+ <source>Volume</source>
+ <translation>Volume</translation>
+ </message>
+ <message>
+ <source>Create a volume</source>
+ <translation>Créer un volume</translation>
+ </message>
+ </context>
- <context>
- <name>Volume:medium</name>
- <message>
- <source>Medium</source>
- <translation>Milieu</translation>
- </message>
- <message>
- <source>Please input the volumes medium</source>
- <translation>Veuillez indiquer le milieu des volumes</translation>
- </message>
- </context>
+ <context>
+ <name>Volume:medium</name>
+ <message>
+ <source>Medium</source>
+ <translation>Milieu</translation>
+ </message>
+ <message>
+ <source>Please input the volumes medium</source>
+ <translation>Veuillez indiquer le milieu des volumes</translation>
+ </message>
+ </context>
- <context>
- <name>Volume:volume_list</name>
- <message>
- <source>Select solids</source>
- <translation>Selectionner les solides</translation>
- </message>
- <message>
- <source>Select solid objects</source>
- <translation>Sélectionnez les solides</translation>
- </message>
- </context>
+ <context>
+ <name>Volume:objects_list</name>
+ <message>
+ <source>Objects</source>
+ <translation>Objets</translation>
+ </message>
+ <message>
+ <source>Select solid objects</source>
+ <translation>Sélectionnez les solides</translation>
+ </message>
+ </context>
- <context>
- <name>Volume:volume_list</name>
- <message>
- <source>Attribute "%1" is not initialized.</source>
- <translation>Sélectionnez les solides.</translation>
- </message>
- </context>
+ <context>
+ <name>Volume:objects_list</name>
+ <message>
+ <source>Attribute "%1" is not initialized.</source>
+ <translation>Sélectionnez les solides.</translation>
+ </message>
+ </context>
</TS>
Volume_1 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Box_1_1")])
### Create a volume from the cylinder and the sphere
-Volume_2 = model.addVolume(Part_1_doc, "Eau", [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Sphere_1_1")])
+Volume_2 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Sphere_1_1")])
+Volume_2.setMedium("Eau")
#Checks
from GeomAPI import GeomAPI_Shape
### Create a volume with no shapes
Volume_4 = model.addVolume(Part_1_doc, "Error", [])
model.testNbResults(Volume_4, 0)
-assert(Volume_4.feature().error() == "Attribute \"volume_list\" is not initialized.")
+assert(Volume_4.feature().error() == "Attribute \"objects_list\" is not initialized.")
### Create a volume with bad shapes
Volume_5 = model.addVolume(Part_1_doc, "Bad Shape", [model.selection("VERTEX", "PartSet/Origin")])
Opera plug-in
==================
-The Opera plug-in contains features for creation of Opera items. Result of each feature is a solid. The plug-in includes the following features:
+The Opera plug-in provides a set of common operations to ROOT geometry. It implements the following features:
.. toctree::
:titlesonly:
- .. tui_create_volume:
+ .. _tui_create_volume:
-Create Box by points
-====================
+Create Volume
+=============
.. literalinclude:: examples/volume.py
:linenos:
:language: python
-:download:`Download this script <examples/volume.py>`
+:download:`Download this script <examples/volume.py>`
+++ /dev/null
-from salome.shaper import model
-
-model.begin()
-partSet = model.moduleDocument()
-Part_1 = model.addPart(partSet)
-Part_1_doc = Part_1.document()
-
-Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
-Volume_1 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Box_1_1")])
-
-model.do()
-model.end()
--- /dev/null
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Volume_1 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Box_1_1")])
+
+model.do()
+model.end()
.. |Volume_button.icon| image:: images/Volume_button.png
Volume
--------------
+------
-Volume feature creates a box solid.
+Volume feature creates a basic object used in bulding the ROOT geometrical hierarchy.
To create a Volume in the active part:
#. select in the Main Menu *Opera - > Volume* item or
#. click |Volume_button.icon| **Volume** button in the toolbar:
-Volume is created by a Medium value and a list of solids
+Volume is created by a value and a list of solids
-.. figure:: images/Volume_create.png
+.. figure:: images/Volume.png
:align: center
Input fields:
-- **MEDIUM**, **VOLUME_LIST** define medium and shapes of the volume.
+- **Medium** defines the name of the medium;
+- **Objects** defines the list of solid objects
**TUI Command**:
-.. py:function:: model.addVolume(Part_doc, MediumString, model.selection["SOLID", "...", ...])
+.. py:function::
+ model.addVolume(Part_doc, medium, model.selection[("SOLID", ...), ...])
:param part: The current part object.
- :param string: Medium name.
- :param list: List of solids.
+ :param string: A medium name.
+ :param list: A list of solids.
:return: Result object.
Result
.. figure:: images/Volume1.png
:align: center
+ Volume created
+
**See Also** a sample TUI Script of :ref:`tui_create_volume` operation.
label="Medium"
tooltip="Please input the volumes medium">
</stringvalue>
- <multi_selector id="volume_list"
- label="Select solids"
+ <multi_selector id="objects_list"
+ label="Objects"
tooltip="Select solid objects"
shape_types="solids"
concealment="true">
<parameter name="PartSet" value="%SHAPER_ROOT_DIR%/share/salome/resources/shaper"/>
<parameter name="XGUI" value="%SHAPER_ROOT_DIR%/share/salome/resources/shaper"/>
</section>
+ <section name="Sketch">
+ <parameter name="operation_cursor" value="1"/>
+ </section>
<section name="Viewer" >
<!-- Viewer preferences -->
<parameter name="face-selection" value="true" />