]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Geom attribute: Point
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 24 Apr 2014 12:36:43 +0000 (16:36 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 24 Apr 2014 12:36:43 +0000 (16:36 +0400)
16 files changed:
CMakeLists.txt
src/GeomAPI/GeomAPI_Pln.cpp
src/GeomAPI/GeomAPI_Pln.h
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h
src/GeomData/CMakeLists.txt [new file with mode: 0644]
src/GeomData/GeomData.h [new file with mode: 0644]
src/GeomData/GeomData_Point.cpp [new file with mode: 0644]
src/GeomData/GeomData_Point.h [new file with mode: 0644]
src/GeomDataAPI/CMakeLists.txt [new file with mode: 0644]
src/GeomDataAPI/GeomDataAPI.h [new file with mode: 0644]
src/GeomDataAPI/GeomDataAPI.i [new file with mode: 0644]
src/GeomDataAPI/GeomDataAPI_Point.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index f29f9a8ba61c9747cc9c805a61fd0535e4d4169e..223001654d8af64d32e6ca78337d7cd769ad1fec 100644 (file)
@@ -26,6 +26,8 @@ ADD_SUBDIRECTORY (src/Model)
 ADD_SUBDIRECTORY (src/ModelAPI)
 ADD_SUBDIRECTORY (src/GeomAPI)
 ADD_SUBDIRECTORY (src/GeomAlgoAPI)
+ADD_SUBDIRECTORY (src/GeomData)
+ADD_SUBDIRECTORY (src/GeomDataAPI)
 ADD_SUBDIRECTORY (src/PartSetPlugin)
 ADD_SUBDIRECTORY (src/ConstructionPlugin)
 ADD_SUBDIRECTORY (src/SketchPlugin)
index d018031022c9dcb84c6a11f0f2a6cd9067769fbe..5780b3d819df8a23ed80928a37b03453e752cc06 100644 (file)
@@ -34,3 +34,8 @@ boost::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::direction()
   const gp_Dir& aDir = impl<gp_Pln>().Axis().Direction();
   return boost::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
 }
+
+void GeomAPI_Pln::coefficients(double& theA, double& theB, double& theC, double& theD)
+{
+  impl<gp_Pln>().Coefficients(theA, theB, theC, theD);
+}
index 0d02084307e85b61f103258541692f69b0ff0bbc..217f743312f92f2cbc4ff700e2eac668387bd77b 100644 (file)
@@ -23,7 +23,7 @@ public:
   GeomAPI_Pln(const boost::shared_ptr<GeomAPI_Pnt>& thePoint,
               const boost::shared_ptr<GeomAPI_Dir>& theNormal);
 
-  /// Creation of plane by coefficients A * X + B * Y + C * Z + D = 0.0 
+  /// Creation of plane by coefficients (Ax+By+Cz+D=0)
   GeomAPI_Pln(const double theA, const double theB, const double theC, const double theD);
 
   /// Returns a point of this plane
@@ -31,6 +31,9 @@ public:
 
   /// Returns a plane normal
   boost::shared_ptr<GeomAPI_Dir> direction();
+
+  /// Returns the plane coefficients (Ax+By+Cz+D=0)
+  void coefficients(double& theA, double& theB, double& theC, double& theD);
 };
 
 #endif
index 40fcc4633133283606b43216bde6fe9a7154b63e..c05fa5a2511e4f9e76d671ecb6c292551fffee0d 100644 (file)
@@ -35,6 +35,7 @@ SET(SWIG_SCRIPTS
 )
 
 SET(SWIG_LINK_LIBRARIES
+  GeomAPI
   GeomAlgoAPI
   ${PYTHON_LIBRARIES}
 )
index 4b2ebc4d26b6adfd3ca7c27a2e31b08961348584..f543c06a669534e26a8d5aa71d42db28ac64e809 100644 (file)
@@ -6,6 +6,9 @@
 #include <gp_Pln.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <TopoDS_Face.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Plane.hxx>
 
 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
   boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Dir> theNormal,
@@ -21,3 +24,22 @@ boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
   aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
   return aRes;
 }
+
+boost::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
+  boost::shared_ptr<GeomAPI_Shape> theFace)
+{
+  boost::shared_ptr<GeomAPI_Pln> aResult;
+  if (!theFace) return aResult; // bad shape
+  TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
+  if (aShape.IsNull()) return aResult; // null shape
+  TopoDS_Face aFace = TopoDS::Face(aShape);
+  if (aFace.IsNull()) return aResult; // not face
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf.IsNull()) return aResult; // no surface
+  Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
+  if (aPlane.IsNull()) return aResult; // not planar
+  double aA, aB, aC, aD;
+  aPlane->Coefficients(aA, aB, aC, aD);
+  aResult = boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+  return aResult;
+}
index 61ebfaeb6139ae0a172f1ab2a6c2213b7a82953d..5d6d731de0c092669735c9e44d242ea64403e8f0 100644 (file)
@@ -8,6 +8,7 @@
 #include <GeomAlgoAPI.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Pln.h>
 #include <GeomAPI_Dir.h>
 #include <boost/shared_ptr.hpp>
 
@@ -23,6 +24,9 @@ public:
   /// normal to the plane and size of square
   static boost::shared_ptr<GeomAPI_Shape> square(boost::shared_ptr<GeomAPI_Pnt> theCenter,
     boost::shared_ptr<GeomAPI_Dir> theNormal, const double theSize);
+
+  /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
+  static boost::shared_ptr<GeomAPI_Pln> plane(boost::shared_ptr<GeomAPI_Shape> theFace);
 };
 
 #endif
diff --git a/src/GeomData/CMakeLists.txt b/src/GeomData/CMakeLists.txt
new file mode 100644 (file)
index 0000000..05ee5eb
--- /dev/null
@@ -0,0 +1,25 @@
+INCLUDE(Common)
+INCLUDE(FindCAS)
+
+SET(PROJECT_HEADERS
+    GeomData.h
+    GeomData_Point.h
+)
+
+SET(PROJECT_SOURCES
+    GeomData_Point.cpp
+)
+
+ADD_DEFINITIONS(-DGEOMDATA_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
+ADD_LIBRARY(GeomData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config)
+
+INCLUDE_DIRECTORIES(
+  ../ModelAPI
+  ../GeomDataAPI
+  ../Events
+  ../Config
+  ${CAS_INCLUDE_DIRS}
+)
+
+INSTALL(TARGETS GeomData DESTINATION bin)
diff --git a/src/GeomData/GeomData.h b/src/GeomData/GeomData.h
new file mode 100644 (file)
index 0000000..c17c76c
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef GEOMDATA_H
+#define GEOMDATA_H
+
+#if defined GEOMDATA_EXPORTS
+#if defined WIN32
+#define GEOMDATA_EXPORT              __declspec( dllexport )
+#else
+#define GEOMDATA_EXPORT
+#endif
+#else
+#if defined WIN32
+#define GEOMDATA_EXPORT              __declspec( dllimport )
+#else
+#define GEOMDATA_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp
new file mode 100644 (file)
index 0000000..9fbb5f4
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        ModelAPI_AttributeDouble.cxx
+// Created:     2 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#include "GeomData_Point.h"
+
+using namespace std;
+
+void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
+{
+  myCoords->SetValue(0, theX);
+  myCoords->SetValue(1, theY);
+  myCoords->SetValue(2, theZ);
+}
+
+double GeomData_Point::x() const
+{
+  return myCoords->Value(0);
+}
+
+double GeomData_Point::y() const
+{
+  return myCoords->Value(1);
+}
+
+double GeomData_Point::z() const
+{
+  return myCoords->Value(2);
+}
+
+GeomData_Point::GeomData_Point(TDF_Label& theLabel)
+{
+  // check the attribute could be already presented in this doc (after load document)
+  if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+    // create attribute: not initialized by value yet, just zero
+    myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
+  }
+}
diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h
new file mode 100644 (file)
index 0000000..06f8495
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        GeomData_Point.h
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomData_Point_HeaderFile
+#define GeomData_Point_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Point.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+
+/**\class GeomData_Point
+ * \ingroup DataModel
+ * \brief Attribute that contains real value with double precision.
+ */
+
+class GeomData_Point : public ModelAPI_Attribute
+{
+  Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
+public:
+  /// Defines the double value
+  virtual void setValue(const double theX, const double theY, const double theZ);
+
+  /// Returns the X double value
+  virtual double x() const;
+  /// Returns the Y double value
+  virtual double y() const;
+  /// Returns the Z double value
+  virtual double z() const;
+
+protected:
+  /// Initializes attributes
+  GeomData_Point(TDF_Label& theLabel);
+};
+
+#endif
diff --git a/src/GeomDataAPI/CMakeLists.txt b/src/GeomDataAPI/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9f09481
--- /dev/null
@@ -0,0 +1,36 @@
+FIND_PACKAGE(SWIG REQUIRED)
+INCLUDE(${SWIG_USE_FILE})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+SET(PROJECT_HEADERS
+    GeomDataAPI.h
+    GeomDataAPI_Point.h
+)
+
+SET(CMAKE_SWIG_FLAGS "")
+
+SET_SOURCE_FILES_PROPERTIES(GeomDataAPI.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(GeomDataAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+
+INCLUDE_DIRECTORIES(
+  ../ModelAPI
+)
+
+SET(SWIG_SCRIPTS
+  ${CMAKE_CURRENT_BINARY_DIR}/GeomDataAPI.py
+)
+
+SET(SWIG_LINK_LIBRARIES
+  ModelAPI
+  ${PYTHON_LIBRARIES}
+)
+
+SWIG_ADD_MODULE(GeomDataAPI python GeomDataAPI.i ${PROJECT_HEADERS})
+SWIG_LINK_LIBRARIES(GeomDataAPI ${SWIG_LINK_LIBRARIES})
+
+IF(WIN32)
+  SET_TARGET_PROPERTIES(_GeomDataAPI PROPERTIES DEBUG_OUTPUT_NAME _GeomDataAPI_d)
+ENDIF(WIN32)
+
+INSTALL(TARGETS _GeomDataAPI DESTINATION swig)
+INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig)
diff --git a/src/GeomDataAPI/GeomDataAPI.h b/src/GeomDataAPI/GeomDataAPI.h
new file mode 100644 (file)
index 0000000..1449986
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef GEOMDATAAPI_H
+#define GEOMDATAAPI_H
+
+#if defined GEOMDATAAPI_EXPORTS
+#if defined WIN32
+#define GEOMDATAAPI_EXPORT              __declspec( dllexport )
+#else
+#define GEOMDATAAPI_EXPORT
+#endif
+#else
+#if defined WIN32
+#define GEOMDATAAPI_EXPORT              __declspec( dllimport )
+#else
+#define GEOMDATAAPI_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/GeomDataAPI/GeomDataAPI.i b/src/GeomDataAPI/GeomDataAPI.i
new file mode 100644 (file)
index 0000000..f759848
--- /dev/null
@@ -0,0 +1,22 @@
+/* GeomDataAPI.i */
+%module GeomDataAPI
+%{
+  #include "GeomDataAPI.h"
+  #include "GeomDataAPI_Point.h"
+  #include <boost/shared_ptr.hpp>
+%}
+
+// to avoid error on this
+#define GEOMDATAAPI_EXPORT
+
+// standard definitions
+%include "typemaps.i"
+%include "std_string.i"
+//%include <std_shared_ptr.i>
+
+// boost pointers
+%include <boost_shared_ptr.i>
+%shared_ptr(GeomDataAPI_Point)
+
+// all supported interfaces
+%include "GeomDataAPI_Point.h"
diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h
new file mode 100644 (file)
index 0000000..d53271f
--- /dev/null
@@ -0,0 +1,41 @@
+// File:        GeomData_AttributeDouble.h
+// Created:     2 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomData_AttributeDouble_HeaderFile
+#define GeomData_AttributeDouble_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomData_AttributeDouble
+ * \ingroup DataModel
+ * \brief Attribute that contains real value with double precision.
+ */
+
+class GeomDataAPI_Point : public ModelAPI_Attribute
+{
+public:
+  /// Defines the double value
+  virtual void setValue(const double theX, const double theY, const double theZ) = 0;
+
+  /// Returns the X double value
+  virtual double x() = 0;
+  /// Returns the Y double value
+  virtual double y() = 0;
+  /// Returns the Z double value
+  virtual double z() = 0;
+
+  /// Returns the type of this class of attributes
+  static inline std::string type() {return std::string("Point");}
+
+  /// Returns the type of this class of attributes, not static method
+  virtual std::string attributeType() {return type();}
+
+protected:
+  /// Objects are created for features automatically
+  GeomDataAPI_Point()
+  {}
+};
+
+#endif
index 2eaa512c80813ea8adb60d0e405f91b6d29e419e..878670ec209066a560bac09d903c460a74ada826 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
@@ -18,7 +19,10 @@ SketchPlugin_Sketch::SketchPlugin_Sketch()
 
 void SketchPlugin_Sketch::initAttributes()
 {
-  //data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_A, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_B, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_C, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_D, ModelAPI_AttributeDouble::type());
 }
 
 void SketchPlugin_Sketch::execute() 
index ed936bde999554a599a9a99dfd9994c3d98ec7f0..ec81fe62e6fc0fe82744163617d108a253e193c8 100644 (file)
@@ -7,11 +7,16 @@
 
 #include "SketchPlugin.h"
 #include <SketchPlugin_Feature.h>
-
 #include <list>
 
-/// part reference attribute
-const std::string PART_ATTR_DOC_REF = "SketchDocument";
+/// Coefficient A of the sketch plane (Ax+By+Cz+D=0)
+const std::string SKETCH_ATTR_PLANE_A("PlaneA");
+/// Coefficient B of the sketch plane
+const std::string SKETCH_ATTR_PLANE_B("PlaneB");
+/// Coefficient C of the sketch plane
+const std::string SKETCH_ATTR_PLANE_C("PlaneC");
+/// Coefficient D of the sketch plane
+const std::string SKETCH_ATTR_PLANE_D("PlaneD");
 
 /**\class SketchPlugin_Sketch
  * \ingroup DataModel
@@ -47,7 +52,6 @@ protected:
   /// \param theShapes the list of result shapes
   void addPlane(double theX, double theY, double theZ,
                 std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
-
 };
 
 #endif