return aSelectionList;
}
+std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
+{
+ return feature()->lastResult();
+}
+
void ModelHighAPI_Interface::throwException(const std::string & theDescription)
{
Events_Error::send(theDescription);
#include <string>
//--------------------------------------------------------------------------------------
class ModelAPI_Feature;
+class ModelAPI_Result;
class ModelHighAPI_Selection;
//--------------------------------------------------------------------------------------
/**\class ModelHighAPI_Interface
MODELHIGHAPI_EXPORT
void execute();
+ // TODO(spo): rename to selectAll()
/// Return all objects of the feature
MODELHIGHAPI_EXPORT
virtual std::list<ModelHighAPI_Selection> result() const;
+ /// Return default result. Default implementation feature()->lastResult()
+ MODELHIGHAPI_EXPORT
+ virtual std::shared_ptr<ModelAPI_Result> defaultResult() const;
+
/// Throw exception to event loop
MODELHIGHAPI_EXPORT
void throwException(const std::string & theDescription);
#include <ModelAPI_Result.h>
#include "ModelHighAPI_Interface.h"
//--------------------------------------------------------------------------------------
-#include <iostream>
-//--------------------------------------------------------------------------------------
ModelHighAPI_RefAttr::ModelHighAPI_RefAttr()
{
}
ModelHighAPI_RefAttr::ModelHighAPI_RefAttr(
const std::shared_ptr<ModelHighAPI_Interface> & theValue)
-: myValue(std::shared_ptr<ModelAPI_Object>(theValue->feature()->firstResult()))
+: myValue(std::shared_ptr<ModelAPI_Object>(theValue->defaultResult()))
{
- // TODO(spo): make firstResult() a member of ModelHighAPI_Interface and use it
}
ModelHighAPI_RefAttr::~ModelHighAPI_RefAttr()
it->appendToList(theAttribute);
}
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
+ const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
+{
+ theAttribute->clear();
+ for (auto it = theValue.begin(); it != theValue.end(); ++it)
+ theAttribute->append(*it);
+}
+
//--------------------------------------------------------------------------------------
void fillAttribute(const ModelHighAPI_Selection & theValue,
const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
class ModelAPI_AttributeString;
+class ModelAPI_Object;
//--------------------------------------------------------------------------------------
class ModelHighAPI_Double;
class ModelHighAPI_Integer;
void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute);
+MODELHIGHAPI_EXPORT
+void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
+ const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute);
+
MODELHIGHAPI_EXPORT
void fillAttribute(const ModelHighAPI_Selection & theValue,
const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute);
model.do()
def test_add_mirror(self):
- mirror = self.sketch.addMirror(
- self.line.result(), self.circle_1.result()
- )
+ mirror = self.sketch.addMirror(self.line, [self.circle_1])
model.do()
mirrored_objects = mirror.mirroredObjects()
mirrored_circle = mirrored_objects.object(0)
circle_feature = ModelAPI_Feature.feature(mirrored_circle)
center = geomDataAPI_Point2D(circle_feature.attribute("CircleCenter"))
- self.assertEqual(center.x(), -30, msg="%s" % center.x())
+ self.assertEqual(center.x(), -30)
# dir(mirrored_circle)
# center = geomDataAPI_Point2D(mirrored_circle.data().attribute("CircleCenter"))
# self.assertEqual(center.x(), -30, msg="%s"%(dir(mirrored_circle)))
SketchAPI_Arc.h
SketchAPI_Circle.h
SketchAPI_Line.h
+ SketchAPI_Mirror.h
SketchAPI_Sketch.h
SketchAPI_SketchEntity.h
SketchAPI_Point.h
SketchAPI_Arc.cpp
SketchAPI_Circle.cpp
SketchAPI_Line.cpp
+ SketchAPI_Mirror.cpp
SketchAPI_Sketch.cpp
SketchAPI_SketchEntity.cpp
SketchAPI_Point.cpp
%shared_ptr(SketchAPI_Arc)
%shared_ptr(SketchAPI_Circle)
%shared_ptr(SketchAPI_Line)
+%shared_ptr(SketchAPI_Mirror)
%shared_ptr(SketchAPI_Sketch)
%shared_ptr(SketchAPI_SketchEntity)
%shared_ptr(SketchAPI_Point)
-// fix compilarion error: ‘res2’ was not declared in this scope
+// TODO(spo): move typemaps into ModelHighAPI package
+
+// fix compilarion error: ‘res*’ was not declared in this scope
%typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
+%typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
%typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
}
}
+%typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
+ std::shared_ptr<ModelAPI_Object> * temp_object;
+ std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+ int newmem = 0;
+ if (PySequence_Check($input)) {
+ for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
+ PyObject * item = PySequence_GetItem($input, i);
+ if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (!temp_object) {
+ PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
+ return NULL;
+ }
+ temp.push_back(*temp_object);
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ delete temp_object;
+ }
+ } else
+ if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+ if (!temp_interface) {
+ PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
+ return NULL;
+ }
+ temp.push_back((*temp_interface)->defaultResult());
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ delete temp_interface;
+ }
+ }
+ Py_DECREF(item);
+ }
+ $1 = &temp;
+ } else {
+ PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
+ return NULL;
+ }
+}
+
// all supported interfaces (the order is very important according dependencies: base class first)
%include "SketchAPI_SketchEntity.h"
%include "SketchAPI_Point.h"
%include "SketchAPI_Line.h"
%include "SketchAPI_Circle.h"
%include "SketchAPI_Arc.h"
+%include "SketchAPI_Mirror.h"
%include "SketchAPI_Sketch.h"
--- /dev/null
+// Name : SketchAPI_Mirror.cpp
+// Purpose:
+//
+// History:
+// 16/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI_Mirror.h"
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+SketchAPI_Mirror::SketchAPI_Mirror(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+ initialize();
+}
+
+SketchAPI_Mirror::SketchAPI_Mirror(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const ModelHighAPI_RefAttr & theMirrorLine,
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if (initialize()) {
+ fillAttribute(theMirrorLine, mirrorLine());
+ fillAttribute(theObjects, mirrorList());
+
+ execute();
+ }
+}
+
+SketchAPI_Mirror::~SketchAPI_Mirror()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
--- /dev/null
+// Name : SketchAPI_Mirror.h
+// Purpose:
+//
+// History:
+// 16/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_MIRROR_H_
+#define SRC_SKETCHAPI_SKETCHAPI_MIRROR_H_
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI.h"
+
+#include <list>
+
+#include <SketchPlugin_ConstraintMirror.h>
+
+#include "SketchAPI_SketchEntity.h"
+//--------------------------------------------------------------------------------------
+class ModelAPI_Object;
+class ModelHighAPI_RefAttr;
+//--------------------------------------------------------------------------------------
+/**\class SketchAPI_Mirror
+ * \ingroup CPPHighAPI
+ * \brief Interface for Mirror feature
+ */
+class SketchAPI_Mirror : public SketchAPI_SketchEntity
+{
+public:
+ /// Constructor without values
+ SKETCHAPI_EXPORT
+ explicit SketchAPI_Mirror(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Mirror(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const ModelHighAPI_RefAttr & theMirrorLine,
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
+ /// Destructor
+ SKETCHAPI_EXPORT
+ virtual ~SketchAPI_Mirror();
+
+ INTERFACE_4(SketchPlugin_ConstraintMirror::ID(),
+ mirrorLine, SketchPlugin_ConstraintMirror::ENTITY_A(), ModelAPI_AttributeRefAttr, /** Mirror line */,
+ mirrorList, SketchPlugin_ConstraintMirror::MIRROR_LIST_ID(), ModelAPI_AttributeRefList, /** Mirror list */,
+ sourceObjects, SketchPlugin_ConstraintMirror::ENTITY_B(), ModelAPI_AttributeRefList, /** Source objects */,
+ mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */
+ )
+
+};
+
+//! Pointer on Mirror object
+typedef std::shared_ptr<SketchAPI_Mirror> MirrorPtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_MIRROR_H_ */
#include "SketchAPI_Arc.h"
#include "SketchAPI_Circle.h"
#include "SketchAPI_Line.h"
+#include "SketchAPI_Mirror.h"
#include "SketchAPI_Point.h"
//--------------------------------------------------------------------------------------
SketchAPI_Sketch::SketchAPI_Sketch(
return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
}
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
+ const ModelHighAPI_RefAttr & theMirrorLine,
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintMirror::ID());
+ return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
+}
+
//--------------------------------------------------------------------------------------
std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
const ModelHighAPI_RefAttr & theLine1,
#include <ModelHighAPI_Macro.h>
//--------------------------------------------------------------------------------------
class ModelAPI_CompositeFeature;
+class ModelAPI_Object;
class ModelHighAPI_Double;
class ModelHighAPI_RefAttr;
class ModelHighAPI_Selection;
class SketchAPI_Arc;
class SketchAPI_Circle;
class SketchAPI_Line;
+class SketchAPI_Mirror;
class SketchAPI_Point;
//--------------------------------------------------------------------------------------
/**\class SketchAPI_Sketch
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
+ /// Add mirror
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Mirror> addMirror(
+ const ModelHighAPI_RefAttr & theMirrorLine,
+ const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
+
/// Set angle
SKETCHAPI_EXPORT
std::shared_ptr<ModelAPI_Feature> setAngle(
const ModelHighAPI_RefAttr & thePoint,
const ModelHighAPI_RefAttr & theLine);
- // TODO(spo): setMirror
-
/// Set parallel
SKETCHAPI_EXPORT
std::shared_ptr<ModelAPI_Feature> setParallel(
#include "SketchAPI_Arc.h"
#include "SketchAPI_Circle.h"
#include "SketchAPI_Line.h"
+ #include "SketchAPI_Mirror.h"
#include "SketchAPI_Sketch.h"
#include "SketchAPI_SketchEntity.h"
#include "SketchAPI_Point.h"