import model
from TestSketcher import SketcherTestCase
-class SketcherAddPoint(SketcherTestCase):
+class SketcherAddPoint(SketcherTestCase):
def test_add_point(self):
point = self.sketch.addPoint(0, 1)
model.do()
- self.assertEqual(point.pointData().x(), 0.0)
- self.assertEqual(point.pointData().y(), 1.0)
-
+ self.assertEqual(point.coordinates().x(), 0.0)
+ self.assertEqual(point.coordinates().y(), 1.0)
+
def test_modify_point(self):
point = self.sketch.addPoint(0, 1)
- point.setValue(1, 2)
+ point.setCoordinates(1, 2)
model.do()
- self.assertEqual(point.pointData().x(), 1.0)
- self.assertEqual(point.pointData().y(), 2.0)
-
- def test_empty_args(self):
- with self.assertRaises(TypeError):
- self.sketch.addPoint()
-
-
+ self.assertEqual(point.coordinates().x(), 1.0)
+ self.assertEqual(point.coordinates().y(), 2.0)
+
if __name__ == "__main__":
unittest.main(verbosity=2)
\ No newline at end of file
SketchAPI_Line.h
SketchAPI_Sketch.h
SketchAPI_SketchEntity.h
+ SketchAPI_Point.h
)
SET(PROJECT_SOURCES
SketchAPI_Line.cpp
SketchAPI_Sketch.cpp
SketchAPI_SketchEntity.cpp
+ SketchAPI_Point.cpp
)
SET(PROJECT_LIBRARIES
%shared_ptr(SketchAPI_Line)
%shared_ptr(SketchAPI_Sketch)
%shared_ptr(SketchAPI_SketchEntity)
+%shared_ptr(SketchAPI_Point)
// fix compilarion error: ‘res2’ was not declared in this scope
%typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
}
}
-// all supported interfaces (the order is very important: base class first)
+// all supported interfaces (the order is very important according dependencies: base class first)
%include "SketchAPI_SketchEntity.h"
-%include "SketchAPI_Arc.h"
-%include "SketchAPI_Circle.h"
+%include "SketchAPI_Point.h"
%include "SketchAPI_Line.h"
+%include "SketchAPI_Circle.h"
+%include "SketchAPI_Arc.h"
%include "SketchAPI_Sketch.h"
--- /dev/null
+// Name : SketchAPI_Point.cpp
+// Purpose:
+//
+// History:
+// 15/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI_Point.h"
+//--------------------------------------------------------------------------------------
+#include <GeomAPI_Pnt2d.h>
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+SketchAPI_Point::SketchAPI_Point(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+ initialize();
+}
+
+SketchAPI_Point::SketchAPI_Point(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ double theX, double theY)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if (initialize()) {
+ setCoordinates(theX, theY);
+ }
+}
+
+SketchAPI_Point::SketchAPI_Point(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if (initialize()) {
+ setCoordinates(thePoint);
+ }
+}
+
+SketchAPI_Point::SketchAPI_Point(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const ModelHighAPI_Selection & theExternal )
+: SketchAPI_SketchEntity(theFeature)
+{
+ if (initialize()) {
+ setByExternal(theExternal);
+ }
+}
+
+SketchAPI_Point::SketchAPI_Point(
+ const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theExternalName )
+: SketchAPI_SketchEntity(theFeature)
+{
+ if (initialize()) {
+ setByExternalName(theExternalName);
+ }
+}
+
+SketchAPI_Point::~SketchAPI_Point()
+{
+
+}
+
+//--------------------------------------------------------------------------------------
+void SketchAPI_Point::setCoordinates(
+ double theX, double theY)
+{
+ fillAttribute(coordinates(), theX, theY);
+
+ execute();
+}
+
+void SketchAPI_Point::setCoordinates(
+ const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
+{
+ fillAttribute(thePoint, coordinates());
+
+ execute();
+}
+
+void SketchAPI_Point::setByExternal(const ModelHighAPI_Selection & theExternal)
+{
+ fillAttribute(theExternal, external());
+
+ execute();
+}
+
+void SketchAPI_Point::setByExternalName(const std::string & theExternalName)
+{
+ fillAttribute(ModelHighAPI_Selection("VERTEX", theExternalName), external());
+
+ execute();
+}
+
+//--------------------------------------------------------------------------------------
--- /dev/null
+// Name : SketchAPI_Point.h
+// Purpose:
+//
+// History:
+// 15/06/16 - Sergey POKHODENKO - Creation of the file
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_POINT_H_
+#define SRC_SKETCHAPI_SKETCHAPI_POINT_H_
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI.h"
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <SketchPlugin_Point.h>
+
+#include "SketchAPI_SketchEntity.h"
+//--------------------------------------------------------------------------------------
+class ModelHighAPI_Selection;
+//--------------------------------------------------------------------------------------
+/**\class SketchAPI_Point
+ * \ingroup CPPHighAPI
+ * \brief Interface for Point feature
+ */
+class SketchAPI_Point : public SketchAPI_SketchEntity
+{
+public:
+ /// Constructor without values
+ SKETCHAPI_EXPORT
+ explicit SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ double theX, double theY);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const ModelHighAPI_Selection & theExternal);
+ /// Constructor with values
+ SKETCHAPI_EXPORT
+ SketchAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+ const std::string & theExternalName);
+ /// Destructor
+ SKETCHAPI_EXPORT
+ virtual ~SketchAPI_Point();
+
+ INTERFACE_2(SketchPlugin_Point::ID(),
+ coordinates, SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D, /** Point coordinates */,
+ external, SketchPlugin_Point::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */
+ )
+
+ /// Set by coordinates
+ SKETCHAPI_EXPORT
+ void setCoordinates(double theX, double theY);
+
+ /// Set by points
+ SKETCHAPI_EXPORT
+ void setCoordinates(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+
+ /// Set by external
+ SKETCHAPI_EXPORT
+ void setByExternal(const ModelHighAPI_Selection & theExternal);
+
+ /// Set by external name
+ SKETCHAPI_EXPORT
+ void setByExternalName(const std::string & theExternalName);
+};
+
+//! Pointer on Point object
+typedef std::shared_ptr<SketchAPI_Point> PointPtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_POINT_H_ */
#include "SketchAPI_Arc.h"
#include "SketchAPI_Circle.h"
#include "SketchAPI_Line.h"
+#include "SketchAPI_Point.h"
//--------------------------------------------------------------------------------------
SketchAPI_Sketch::SketchAPI_Sketch(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
}
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
+ double theX, double theY)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+ return PointPtr(new SketchAPI_Point(aFeature, theX, theY));
+}
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+ return PointPtr(new SketchAPI_Point(aFeature, thePoint));
+}
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+ return PointPtr(new SketchAPI_Point(aFeature, theExternal));
+}
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID());
+ return PointPtr(new SketchAPI_Point(aFeature, theExternalName));
+}
+
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
{
class SketchAPI_Arc;
class SketchAPI_Circle;
class SketchAPI_Line;
+class SketchAPI_Point;
//--------------------------------------------------------------------------------------
/**\class SketchAPI_Sketch
* \ingroup CPPHighAPI
SKETCHAPI_EXPORT
void setExternal(const ModelHighAPI_Selection & theExternal);
- // TODO(spo): addPoint
+ // TODO(spo): addIntersection
+
+ /// Add point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Point> addPoint(
+ double theX, double theY);
+ /// Add point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Point> addPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d> & thePoint);
+ /// Add point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Point> addPoint(const ModelHighAPI_Selection & theExternal);
+ /// Add point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Point> addPoint(const std::string & theExternalName);
/// Add line
SKETCHAPI_EXPORT
#include "SketchAPI_Line.h"
#include "SketchAPI_Sketch.h"
#include "SketchAPI_SketchEntity.h"
+ #include "SketchAPI_Point.h"
#endif /* SRC_SKETCHAPI_SKETCHAPI_SWIG_H_ */