ADD_UNIT_TESTS(TestAxisCreation.py
UnitTestAxis.py
- TestPointName.py
TestPoint.py
+ TestPointName.py
TestPlane.py)
{
Standard_Boolean aValue = theValue ? Standard_True : Standard_False;
if (!myIsInitialized || myBool->Get() != aValue) {
+ if (myBool.IsNull())
+ myBool = TDataStd_Integer::Set(myLab, 0);
myBool->Set(aValue);
owner()->data()->sendAttributeUpdated(this);
}
bool Model_AttributeBoolean::value()
{
- return myBool->Get() == Standard_True ;
+ return myIsInitialized && myBool->Get() == Standard_True ;
}
Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
{
+ myLab = theLabel;
// check the attribute could be already presented in this doc (after load document)
myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool) == Standard_True;
- if (!myIsInitialized) {
- // create attribute: not initialized by value yet, just zero
- myBool = TDataStd_Integer::Set(theLabel, 0);
- }
}
class Model_AttributeBoolean : public ModelAPI_AttributeBoolean
{
Handle_TDataStd_Integer myBool; ///< double is Real attribute
+ TDF_Label myLab; ///< if attribute is not initialized, store label here
public:
/// Defines the double value
MODEL_EXPORT virtual void setValue(bool theValue);
{
TCollection_ExtendedString aValue(theValue.c_str());
if (!myIsInitialized || myString->Get() != aValue) {
+ if (myString.IsNull())
+ myString = TDataStd_Name::Set(myLab, TCollection_ExtendedString());
myString->Set(aValue);
owner()->data()->sendAttributeUpdated(this);
}
std::string Model_AttributeString::value()
{
+ if (myString.IsNull())
+ return ""; // not initialized
return TCollection_AsciiString(myString->Get()).ToCString();
}
Model_AttributeString::Model_AttributeString(TDF_Label& theLabel)
{
+ myLab = theLabel;
// check the attribute could be already presented in this doc (after load document)
myIsInitialized = theLabel.FindAttribute(TDataStd_Name::GetID(), myString) == Standard_True;
- if (!myIsInitialized) {
- // create attribute: not initialized by value yet, just empty string
- myString = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
- }
}
class Model_AttributeString : public ModelAPI_AttributeString
{
- Handle_TDataStd_Name myString;
+ Handle_TDataStd_Name myString; ///< container of the string value
+ TDF_Label myLab; ///< if attribute is not initialized, store label here
public:
/// Defines the std::string value
MODEL_EXPORT virtual void setValue(const std::string& theValue);
: Model_Expression(theLabel)
{
if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
- myReal = TDataStd_Real::Set(theLabel, 0.);
myIsInitialized = false;
// MPV: temporarily to support the previously saved files (to check and resolve bugs), to be removed
Handle(TDataStd_RealArray) anOldArray;
if (theLabel.Father().FindAttribute(TDataStd_RealArray::GetID(), anOldArray) == Standard_True) {
+ myReal = TDataStd_Real::Set(theLabel, 0.);
myReal->Set(anOldArray->Value(theLabel.Tag() - 1));
myIsInitialized = true;
Handle(TDataStd_ExtStringArray) anOldExp;
Handle(TDataStd_Real) anOldReal;
if (theLabel.Father().FindAttribute(TDataStd_Real::GetID(), anOldReal)) {
myIsInitialized = true;
+ myReal = TDataStd_Real::Set(theLabel, 0.);
myReal->Set(anOldReal->Get());
Handle(TDataStd_Name) aText;
if (theLabel.Father().FindAttribute(TDataStd_Name::GetID(), aText)) {
void Model_ExpressionDouble::setValue(const double theValue)
{
- if (value() != theValue)
+ if (!myIsInitialized) {
+ myReal = TDataStd_Real::Set(myText->Label(), theValue);
+ myIsInitialized = true;
+ } else if (value() != theValue) {
myReal->Set(theValue);
+ }
}
double Model_ExpressionDouble::value()
{
- return myReal->Get();
+ if (myIsInitialized)
+ return myReal->Get();
+ return -1.; // error
}
void Model_ExpressionDouble::setInvalid(const bool theFlag)
{
if (theFlag) {
- TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
+ TDataStd_UAttribute::Set(myText->Label(), kInvalidGUID);
} else {
- myReal->Label().ForgetAttribute(kInvalidGUID);
+ myText->Label().ForgetAttribute(kInvalidGUID);
}
}
bool Model_ExpressionDouble::isInvalid()
{
- return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
+ return myText->Label().IsAttribute(kInvalidGUID) == Standard_True;
}
: Model_Expression(theLabel)
{
if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger)) {
- myInteger = TDataStd_Integer::Set(theLabel, 0);
myIsInitialized = false;
} else
myIsInitialized = true;
void Model_ExpressionInteger::setValue(const int theValue)
{
- if (value() != theValue)
+ if (!myIsInitialized) {
+ myInteger = TDataStd_Integer::Set(myText->Label(), theValue);
+ myIsInitialized = true;
+ } else if (value() != theValue) {
myInteger->Set(theValue);
+ }
}
int Model_ExpressionInteger::value()
{
- return myInteger->Get();
+ if (myIsInitialized)
+ return myInteger->Get();
+ return -1; // error
}
void Model_ExpressionInteger::setInvalid(const bool theFlag)
{
if (theFlag) {
- TDataStd_UAttribute::Set(myInteger->Label(), kInvalidGUID);
+ TDataStd_UAttribute::Set(myText->Label(), kInvalidGUID);
} else {
- myInteger->Label().ForgetAttribute(kInvalidGUID);
+ myText->Label().ForgetAttribute(kInvalidGUID);
}
}
bool Model_ExpressionInteger::isInvalid()
{
- return myInteger->Label().IsAttribute(kInvalidGUID) == Standard_True;
+ return myText->Label().IsAttribute(kInvalidGUID) == Standard_True;
}
#=========================================================================
# End of test
#=========================================================================
-
-import model
-assert(model.checkPythonDump())
aPartSet = aSession.moduleDocument()
aSession.startOperation()
aSketchFeature = featureToCompositeFeature(aPartSet.addFeature("Sketch"))
+aXOYPlane = objectToResult(aPartSet.objectByName("Construction", "XOY"))
+aSketchFeature.selection("External").setValue(aXOYPlane, None)
aFeatureData = aSketchFeature.data()
anArray = aFeatureData.addAttribute("IntArray_1", "IntArray")
aFeatureData.intArray("IntArray_1").setSize(5)
+aSession.finishOperation()
+
assert(aFeatureData.intArray("IntArray_1").size() == 5)
#=========================================================================
# End of test
#=========================================================================
-
-import model
-assert(model.checkPythonDump())
#include <GeomAPI_Ax3.h>
#include <GeomAPI_Pnt.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
#include <cmath>
return std::string();
}
+std::shared_ptr<ModelAPI_Result> standardPlane(const std::string & theName){
+ DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
+ // searching for the construction element
+ return std::dynamic_pointer_cast<ModelAPI_Result>(
+ aPartSet->objectByName(ModelAPI_ResultConstruction::group(), theName));
+}
+
//--------------------------------------------------------------------------------------
void begin()
{
class GeomAPI_Dir;
class GeomAPI_Pnt;
class ModelAPI_Document;
+class ModelAPI_Result;
//--------------------------------------------------------------------------------------
/// Return the main document (the Partset) created or open from the Modeler.
MODELHIGHAPI_EXPORT
const std::shared_ptr<GeomAPI_Dir>& theNormal,
const std::shared_ptr<GeomAPI_Dir>& theDirX);
+/** Return one of the three standard results defined in PartSet document.
+ *
+ * These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0).
+ */
+MODELHIGHAPI_EXPORT
+std::shared_ptr<ModelAPI_Result> standardPlane(const std::string & theName);
+
/** Start a data structure transaction.
*
* Make a control point for being able to discard or undo
#include <Events_InfoMessage.h>
+// Have to be included before std headers
+#include <Python.h>
+
#include <algorithm>
#include <iostream>
// close all before importation of the script
aSession->closeAll();
// execute the dumped
- Config_ModuleReader::loadScript("check_dump");
+ PyGILState_STATE gstate = PyGILState_Ensure(); /* acquire python thread */
+ PyObject* PyFileObject = PyFile_FromString("./check_dump.py", "r");
+ PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), "./check_dump.py", 1);
+ PyGILState_Release(gstate); /* release python thread */
// compare with the stored data
anError = storeFeatures(
"""
from ModelHighAPI import moduleDocument, activeDocument
-from ModelHighAPI import defaultPlane
+from ModelHighAPI import defaultPlane, standardPlane
from ModelHighAPI import begin, end
from ModelHighAPI import apply as do
from ModelHighAPI import undo, redo
}
}
+SketchAPI_Sketch::SketchAPI_Sketch(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ std::shared_ptr<ModelAPI_Object> thePlaneObject)
+: ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ setExternal(thePlaneObject);
+ }
+}
+
SketchAPI_Sketch::~SketchAPI_Sketch()
{
execute();
}
+void SketchAPI_Sketch::setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject)
+{
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePlaneObject);
+ ModelHighAPI_Selection aSel(aRes);
+ setExternal(aSel);
+}
+
//--------------------------------------------------------------------------------------
void SketchAPI_Sketch::setValue(
const std::shared_ptr<ModelAPI_Feature> & theConstraint,
return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
}
+SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
+ std::shared_ptr<ModelAPI_Object> thePlaneObject)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
+ return SketchPtr(new SketchAPI_Sketch(aFeature, thePlaneObject));
+}
+
+
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
double theX, double theY)
// Check the plane is coordinate plane
std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
- if (aPlaneName.empty()) {
- // needs import additional module
- theDumper.importModule("GeomAPI");
- // dump plane parameters
- const std::string& aSketchName = theDumper.name(aBase);
- std::string anOriginName = aSketchName + "_origin";
- std::string aNormalName = aSketchName + "_norm";
- std::string aDirXName = aSketchName + "_dirx";
- theDumper << anOriginName << " = " << anOrigin << std::endl
- << aNormalName << " = " << aNormal << std::endl
- << aDirXName << " = " << aDirX << std::endl;
- // dump sketch based on arbitrary plane
- theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
- << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
+ if (anExternal->context()) { // checking for selected planes
+ if (!aPlaneName.empty()) {
+ // dump sketch based on coordinate plane
+ theDumper << aBase << " = model.addSketch(" << aDocName
+ << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;
+ } else { // some other plane
+ theDumper << aBase << " = model.addSketch(" << aDocName << ", " << anExternal<< ")" << std::endl;
+ }
} else {
- // dump sketch based on coordinate plane
- theDumper << aBase << " = model.addSketch(" << aDocName
- << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
+ if (aPlaneName.empty()) {
+ // needs import additional module
+ theDumper.importModule("GeomAPI");
+ // dump plane parameters
+ const std::string& aSketchName = theDumper.name(aBase);
+ std::string anOriginName = aSketchName + "_origin";
+ std::string aNormalName = aSketchName + "_norm";
+ std::string aDirXName = aSketchName + "_dirx";
+ theDumper << anOriginName << " = " << anOrigin << std::endl
+ << aNormalName << " = " << aNormal << std::endl
+ << aDirXName << " = " << aDirX << std::endl;
+ // dump sketch based on arbitrary plane
+ theDumper << aBase << " = model.addSketch(" << aDocName << ", GeomAPI_Ax3("
+ << anOriginName << ", " << aDirXName << ", " << aNormalName << "))" << std::endl;
+ } else {
+ // dump sketch based on coordinate plane
+ theDumper << aBase << " = model.addSketch(" << aDocName
+ << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
+ }
}
}
SKETCHAPI_EXPORT
SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
const ModelHighAPI_Selection & theExternal);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Sketch(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ std::shared_ptr<ModelAPI_Object> thePlaneObject);
/// Destructor
SKETCHAPI_EXPORT
virtual ~SketchAPI_Sketch();
SKETCHAPI_EXPORT
void setExternal(const ModelHighAPI_Selection & theExternal);
+ /// Set external
+ SKETCHAPI_EXPORT
+ void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
+
/// Add point
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Point> addPoint(
SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theExternalName);
+/**\ingroup CPPHighAPI
+ * \brief Create Sketch feature
+ */
+SKETCHAPI_EXPORT
+SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
+ std::shared_ptr<ModelAPI_Object> thePlaneObject);
+
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
#endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */