INCLUDE_DIRECTORIES(
# TODO(spo): modify ConstructionPlugin headers to remove dependency on GeomAPI headers
${PROJECT_SOURCE_DIR}/src/GeomAPI
+ # TODO(spo): it is for *_swig.h files. Can we eliminate it?
+ ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
${PROJECT_SOURCE_DIR}/src/ConstructionPlugin
)
# Plugin headers dependency
INCLUDE_DIRECTORIES(
- # TODO(spo): modify ConstructionPlugin headers to remove dependency on GeomAPI headers
+ # TODO(spo): modify ExchangePlugin headers to remove dependency on GeomAPI headers
${PROJECT_SOURCE_DIR}/src/GeomAPI
+ ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
${PROJECT_SOURCE_DIR}/src/ExchangePlugin
)
import ModelAPI
import ExchangeAPI
-class PointTestCase(unittest.TestCase):
+class ExchangeTestCase(unittest.TestCase):
def setUp(self):
self.session = ModelAPI.ModelAPI_Session.get()
#ifndef SRC_GEOMDATAAPI_GEOMDATAAPI_SWIG_H_
#define SRC_GEOMDATAAPI_GEOMDATAAPI_SWIG_H_
- #include "ModelAPI_swig.h"
+ #include <ModelAPI_swig.h>
#include "GeomDataAPI.h"
#include "GeomDataAPI_Point.h"
ModelHighAPI_Integer.h
ModelHighAPI_Interface.h
ModelHighAPI_Macro.h
+ ModelHighAPI_RefAttr.h
ModelHighAPI_Selection.h
ModelHighAPI_Tools.h
)
ModelHighAPI_Double.cpp
ModelHighAPI_Integer.cpp
ModelHighAPI_Interface.cpp
+ ModelHighAPI_RefAttr.cpp
ModelHighAPI_Selection.cpp
ModelHighAPI_Tools.cpp
)
ADD_UNIT_TESTS(
TestDouble.py
TestInteger.py
+ TestRefAttr.py
)
# ADD_SUBDIRECTORY (Test)
%include "doxyhelp.i"
+// import other modules
+%import "ModelAPI.i"
+%import "GeomDataAPI.i"
+
// to avoid error on this
#define MODELHIGHAPI_EXPORT
return NULL;
}
}
-
%typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Double, const ModelHighAPI_Double & {
$1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input)) ? 1 : 0;
}
return NULL;
}
}
-
%typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Integer, const ModelHighAPI_Integer & {
$1 = (PyInt_Check($input) || PyString_Check($input)) ? 1 : 0;
}
+%typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) {
+ std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
+ std::shared_ptr<ModelAPI_Object> * temp_object;
+ int newmem = 0;
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ temp = ModelHighAPI_RefAttr(*temp_attribute);
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ delete temp_attribute;
+ }
+ $1 = &temp;
+ } else
+ if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ temp = ModelHighAPI_RefAttr(*temp_object);
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ delete temp_object;
+ }
+ $1 = &temp;
+ } else
+ if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
+ } else {
+ PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Double, float, int or string.");
+ return NULL;
+ }
+}
+
// all supported interfaces
%include "ModelHighAPI_Double.h"
%include "ModelHighAPI_Integer.h"
%include "ModelHighAPI_Interface.h"
%include "ModelHighAPI_Macro.h"
+%include "ModelHighAPI_RefAttr.h"
%include "ModelHighAPI_Selection.h"
%include "ModelHighAPI_Tools.h"
-
-// std::list -> []
-%template(SelectionList) std::list<ModelHighAPI_Selection>;
#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_
#define SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_
+//--------------------------------------------------------------------------------------
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
//--------------------------------------------------------------------------------------
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDocRef.h>
--- /dev/null
+// Name : ModelHighAPI_RefAttr.cpp
+// Purpose:
+//
+// History:
+// 08/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI_RefAttr.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+//--------------------------------------------------------------------------------------
+#include <iostream>
+//--------------------------------------------------------------------------------------
+ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
+{
+}
+
+ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
+ const std::shared_ptr<ModelAPI_Attribute> & theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
+ const std::shared_ptr<ModelAPI_Object> & theValue)
+: myValue(theValue)
+{
+}
+
+ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
+{
+}
+
+//--------------------------------------------------------------------------------------
+struct fill_visitor : boost::static_visitor<void>
+{
+ mutable std::shared_ptr<ModelAPI_AttributeRefAttr> myAttribute;
+
+ fill_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
+ : myAttribute(theAttribute) {}
+
+ void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->setAttr(theValue); }
+ void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->setObject(theValue); }
+};
+
+void ModelHighAPI_RefAttr::fillAttribute(
+ const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const
+{
+ boost::apply_visitor(fill_visitor(theAttribute), myValue);
+}
--- /dev/null
+// Name : ModelHighAPI_RefAttr.h
+// Purpose:
+//
+// History:
+// 08/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_REFATTR_H_
+#define SRC_MODELHIGHAPI_MODELHIGHAPI_REFATTR_H_
+
+//--------------------------------------------------------------------------------------
+#include "ModelHighAPI.h"
+
+#include <memory>
+#include <string>
+
+#include <boost/variant.hpp>
+//--------------------------------------------------------------------------------------
+class ModelAPI_Attribute;
+class ModelAPI_AttributeRefAttr;
+class ModelAPI_Object;
+//--------------------------------------------------------------------------------------
+/**\class ModelHighAPI_RefAttr
+ * \ingroup CPPHighAPI
+ * \brief Class for filling ModelAPI_AttributeRefAttr
+ */
+class ModelHighAPI_RefAttr
+{
+public:
+ /// Default constructor
+ MODELHIGHAPI_EXPORT
+ ModelHighAPI_RefAttr();
+ /// Constructor for attribute
+ MODELHIGHAPI_EXPORT
+ explicit ModelHighAPI_RefAttr(const std::shared_ptr<ModelAPI_Attribute> & theValue);
+ /// Constructor for object
+ MODELHIGHAPI_EXPORT
+ explicit ModelHighAPI_RefAttr(const std::shared_ptr<ModelAPI_Object> & theValue);
+ /// Destructor
+ MODELHIGHAPI_EXPORT
+ virtual ~ModelHighAPI_RefAttr();
+
+ /// Fill attribute values
+ MODELHIGHAPI_EXPORT
+ virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const;
+
+private:
+ boost::variant<
+ std::shared_ptr<ModelAPI_Attribute>,
+ std::shared_ptr<ModelAPI_Object>
+ > myValue;
+};
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_REFATTR_H_ */
//--------------------------------------------------------------------------------------
#include "ModelHighAPI_Double.h"
#include "ModelHighAPI_Integer.h"
+#include "ModelHighAPI_RefAttr.h"
#include "ModelHighAPI_Selection.h"
//--------------------------------------------------------------------------------------
theValue.fillAttribute(theAttribute);
}
+//--------------------------------------------------------------------------------------
+void fillAttribute(const ModelHighAPI_RefAttr & theValue,
+ const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
+{
+ theValue.fillAttribute(theAttribute);
+}
+
//--------------------------------------------------------------------------------------
void fillAttribute(const ModelHighAPI_Selection & theValue,
const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
//--------------------------------------------------------------------------------------
class ModelHighAPI_Double;
class ModelHighAPI_Integer;
+class ModelHighAPI_RefAttr;
class ModelHighAPI_Selection;
//--------------------------------------------------------------------------------------
MODELHIGHAPI_EXPORT
void fillAttribute(const ModelHighAPI_Integer & theValue,
const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
+MODELHIGHAPI_EXPORT
+void fillAttribute(const ModelHighAPI_RefAttr & theValue,
+ const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute);
+
MODELHIGHAPI_EXPORT
void fillAttribute(const ModelHighAPI_Selection & theValue,
const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute);
#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_
#define SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_
- #include <ModelAPI.h>
+ #include <ModelAPI_swig.h>
+ #include <GeomDataAPI_swig.h>
#include "ModelHighAPI.h"
#include "ModelHighAPI_Double.h"
#include "ModelHighAPI_Integer.h"
#include "ModelHighAPI_Interface.h"
#include "ModelHighAPI_Macro.h"
+ #include "ModelHighAPI_RefAttr.h"
#include "ModelHighAPI_Selection.h"
#include "ModelHighAPI_Tools.h"
--- /dev/null
+import unittest
+
+import ModelAPI
+import ModelHighAPI
+import model
+
+class FeaturesFixture(unittest.TestCase):
+
+ def setUp(self):
+ model.begin()
+ # Create part
+ partset = model.moduleDocument()
+ self.part = model.addPart(partset).document()
+ model.do()
+ self.feature = model.addPoint(self.part, 0, 0, 0)
+
+ def tearDown(self):
+ model.end()
+ model.reset()
+
+
+class RefAttrTestCase(FeaturesFixture):
+
+ def test_create_default(self):
+ ModelHighAPI.ModelHighAPI_RefAttr()
+
+ def test_create_from_attribute(self):
+ print(self.feature.x())
+ ModelHighAPI.ModelHighAPI_RefAttr(self.feature.x())
+
+ def test_create_from_object(self):
+ ModelHighAPI.ModelHighAPI_RefAttr(self.feature.feature())
+
+ def test_create_from_None(self):
+ ModelHighAPI.ModelHighAPI_RefAttr(None)
+
+
+if __name__ == "__main__":
+ unittest.main()
import model
from TestSketcher import SketcherTestCase
-class SketcherSetCoincident(SketcherTestCase):
+class SketcherSetCoincident(SketcherTestCase):
def test_set_coincident(self):
l1 = self.sketch.addLine(0, 0, 0, 1)
l2 = self.sketch.addLine(0, 1, 1, 1)
self.sketch.setCoincident(l1.endPoint(), l2.startPoint())
model.do()
-
- def test_none_type_arguments(self):
- l2 = self.sketch.addLine(0, 1, 1, 1)
- with self.assertRaises(TypeError):
- self.sketch.setCoincident(None, l2.startPoint())
-
+
+# def test_none_type_arguments(self):
+# l2 = self.sketch.addLine(0, 1, 1, 1)
+# with self.assertRaises(TypeError):
+# self.sketch.setCoincident(None, l2.startPoint())
+
def test_empty_arguments(self):
l1 = self.sketch.addLine(0, 0, 0, 1)
with self.assertRaises(TypeError):
//--------------------------------------------------------------------------------------
#include "SketchAPI_Sketch.h"
//--------------------------------------------------------------------------------------
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintAngle.h>
+//#include <SketchPlugin_ConstraintBase.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintEqual.h>
+#include <SketchPlugin_ConstraintFillet.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
+#include <SketchPlugin_ConstraintMirror.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_ConstraintVertical.h>
+//--------------------------------------------------------------------------------------
#include <ModelAPI_CompositeFeature.h>
#include <ModelHighAPI_Tools.h>
#include "SketchAPI_Line.h"
}
//--------------------------------------------------------------------------------------
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
+ const ModelHighAPI_RefAttr & thePoint1,
+ const ModelHighAPI_RefAttr & thePoint2)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
+ fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
+ aFeature->execute();
+ return aFeature;
+}
+
+//--------------------------------------------------------------------------------------
+void SketchAPI_Sketch::setValue(
+ const std::shared_ptr<ModelAPI_Feature> & theConstraint,
+ const ModelHighAPI_Double & theValue)
+{
+ fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
+}
+
+//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
class ModelAPI_CompositeFeature;
class ModelHighAPI_Double;
+class ModelHighAPI_RefAttr;
class ModelHighAPI_Selection;
class SketchAPI_Line;
//--------------------------------------------------------------------------------------
// TODO(spo): addCircle
// TODO(spo): addArc
+ /// Set coincident
+ SKETCHAPI_EXPORT
+ std::shared_ptr<ModelAPI_Feature> setCoincident(
+ // TODO(spo): should it be more concrete type (e.g. ModelAPI_Object)?
+ const ModelHighAPI_RefAttr & thePoint1,
+ const ModelHighAPI_RefAttr & thePoint2);
+
// TODO(spo): set* (constraints)
- // TODO(spo): setValue
- // TODO(spo): setText
+ // TODO(spo): addMirror
+
+ /// Set value
+ SKETCHAPI_EXPORT
+ void setValue(
+ const std::shared_ptr<ModelAPI_Feature> & theConstraint,
+ const ModelHighAPI_Double & theValue);
+
+ // TODO(spo): setText. Is it necessary as setValue accepts text expressions?
protected:
std::shared_ptr<ModelAPI_CompositeFeature> compositeFeature() const;
import unittest
import ModelAPI
-import ExchangeAPI
+import SketchAPI
-class PointTestCase(unittest.TestCase):
+class SketchTestCase(unittest.TestCase):
def setUp(self):
self.session = ModelAPI.ModelAPI_Session.get()
def tearDown(self):
self.session.closeAll()
- def test_addImport(self):
- self.session.startOperation()
- self.feature = ExchangeAPI.addImport(self.doc, "file_path")
- self.session.finishOperation()
-
- def test_addExport(self):
- self.session.startOperation()
- self.feature = ExchangeAPI.exportToFile(self.doc, "file_path", "file_format", [])
- self.session.finishOperation()
+# TODO(spo): add tests.
if __name__ == "__main__":
unittest.main()