Salome HOME
Sketch line feature based on points attributes
authormpv <mikhail.ponikarov@opencascade.com>
Fri, 25 Apr 2014 09:20:16 +0000 (13:20 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Fri, 25 Apr 2014 09:20:16 +0000 (13:20 +0400)
28 files changed:
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h [new file with mode: 0644]
src/GeomData/CMakeLists.txt
src/GeomData/GeomData_Dir.cpp [new file with mode: 0644]
src/GeomData/GeomData_Dir.h [new file with mode: 0644]
src/GeomData/GeomData_Point.cpp
src/GeomData/GeomData_Point.h
src/GeomData/GeomData_Point2D.cpp [new file with mode: 0644]
src/GeomData/GeomData_Point2D.h [new file with mode: 0644]
src/GeomDataAPI/CMakeLists.txt
src/GeomDataAPI/GeomDataAPI.i
src/GeomDataAPI/GeomDataAPI_Dir.h [new file with mode: 0644]
src/GeomDataAPI/GeomDataAPI_Point.h
src/GeomDataAPI/GeomDataAPI_Point2D.h [new file with mode: 0644]
src/Model/CMakeLists.txt
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_Attribute.h
src/ModelAPI/ModelAPI_Data.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_OperationSketch.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Line.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index c05fa5a2511e4f9e76d671ecb6c292551fffee0d..509c7fd9e0bc5ab7b01c1f3dc608e14e237709ab 100644 (file)
@@ -8,11 +8,13 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI.h
     GeomAlgoAPI_CompoundBuilder.h
     GeomAlgoAPI_FaceBuilder.h
+    GeomAlgoAPI_EdgeBuilder.h
 )
 
 SET(PROJECT_SOURCES
     GeomAlgoAPI_CompoundBuilder.cpp
     GeomAlgoAPI_FaceBuilder.cpp
+    GeomAlgoAPI_EdgeBuilder.cpp
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
new file mode 100644 (file)
index 0000000..c8419fe
--- /dev/null
@@ -0,0 +1,24 @@
+// File:        GeomAlgoAPI_EdgeBuilder.cpp
+// Created:     23 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <gp_Pln.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Plane.hxx>
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
+  boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
+{
+  const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
+  const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
+
+  BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
+  boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  aRes->setImpl(new TopoDS_Shape(anEdge));
+  return aRes;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h
new file mode 100644 (file)
index 0000000..cd505a8
--- /dev/null
@@ -0,0 +1,26 @@
+// File:        GeomAlgoAPI_EdgeBuilder.h
+// Created:     23 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomAlgoAPI_EdgeBuilder_HeaderFile
+#define GeomAlgoAPI_EdgeBuilder_HeaderFile
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Pnt.h>
+#include <boost/shared_ptr.hpp>
+
+/**\class GeomAlgoAPI_EdgeBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder
+{
+public:
+  /// Creates linear edge by two points
+  static boost::shared_ptr<GeomAPI_Shape> line(
+    boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd);
+};
+
+#endif
index 05ee5eb3c7f806995e8d492ae0b96dbf73e70a9b..39f76ff1571b7365ecb44e34eeaa89686ee20bdd 100644 (file)
@@ -4,15 +4,19 @@ INCLUDE(FindCAS)
 SET(PROJECT_HEADERS
     GeomData.h
     GeomData_Point.h
+    GeomData_Dir.h
+    GeomData_Point2D.h
 )
 
 SET(PROJECT_SOURCES
     GeomData_Point.cpp
+    GeomData_Dir.cpp
+    GeomData_Point2D.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)
+TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI)
 
 INCLUDE_DIRECTORIES(
   ../ModelAPI
diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp
new file mode 100644 (file)
index 0000000..dc2ca12
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        GeomData_Dir.cxx
+// Created:     2 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#include "GeomData_Dir.h"
+
+using namespace std;
+
+void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
+{
+  myCoords->SetValue(0, theX);
+  myCoords->SetValue(1, theY);
+  myCoords->SetValue(2, theZ);
+}
+
+double GeomData_Dir::x() const
+{
+  return myCoords->Value(0);
+}
+
+double GeomData_Dir::y() const
+{
+  return myCoords->Value(1);
+}
+
+double GeomData_Dir::z() const
+{
+  return myCoords->Value(2);
+}
+
+GeomData_Dir::GeomData_Dir(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_Dir.h b/src/GeomData/GeomData_Dir.h
new file mode 100644 (file)
index 0000000..554fd04
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        GeomData_Dir.h
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomData_Dir_HeaderFile
+#define GeomData_Dir_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Dir.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+
+/**\class GeomData_Dir
+ * \ingroup DataModel
+ * \brief Attribute that contains direction.
+ */
+class GeomData_Dir : public GeomDataAPI_Dir
+{
+  Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
+public:
+  /// Defines the double value
+  GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
+
+  /// Returns the X double value
+  GEOMDATA_EXPORT virtual double x() const;
+  /// Returns the Y double value
+  GEOMDATA_EXPORT virtual double y() const;
+  /// Returns the Z double value
+  GEOMDATA_EXPORT virtual double z() const;
+
+protected:
+  /// Initializes attributes
+  GEOMDATA_EXPORT GeomData_Dir(TDF_Label& theLabel);
+
+  friend class Model_Data;
+};
+
+#endif
index 9fbb5f4243fad2d51ce217dd5f32a76b6661eed6..6f57d4157225eea930577ce8acb462d4820821ab 100644 (file)
@@ -1,5 +1,5 @@
-// File:        ModelAPI_AttributeDouble.cxx
-// Created:     2 Apr 2014
+// File:        GeomData_Point.cxx
+// Created:     24 Apr 2014
 // Author:      Mikhail PONIKAROV
 
 #include "GeomData_Point.h"
index 06f84959ac05f1f3fe87192b9a6e93945b9837c0..9886333c2fb63e5ac219a1d12a2b5b5e3a836c57 100644 (file)
 
 /**\class GeomData_Point
  * \ingroup DataModel
- * \brief Attribute that contains real value with double precision.
+ * \brief Attribute that contains 3D point.
  */
 
-class GeomData_Point : public ModelAPI_Attribute
+class GeomData_Point : public GeomDataAPI_Point
 {
   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);
+  GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
 
   /// Returns the X double value
-  virtual double x() const;
+  GEOMDATA_EXPORT virtual double x() const;
   /// Returns the Y double value
-  virtual double y() const;
+  GEOMDATA_EXPORT virtual double y() const;
   /// Returns the Z double value
-  virtual double z() const;
+  GEOMDATA_EXPORT virtual double z() const;
 
 protected:
   /// Initializes attributes
-  GeomData_Point(TDF_Label& theLabel);
+  GEOMDATA_EXPORT GeomData_Point(TDF_Label& theLabel);
+
+  friend class Model_Data;
 };
 
 #endif
diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp
new file mode 100644 (file)
index 0000000..3e57622
--- /dev/null
@@ -0,0 +1,32 @@
+// File:        GeomData_Point2D.cxx
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#include "GeomData_Point2D.h"
+
+using namespace std;
+
+void GeomData_Point2D::setValue(const double theX, const double theY)
+{
+  myCoords->SetValue(0, theX);
+  myCoords->SetValue(1, theY);
+}
+
+double GeomData_Point2D::x() const
+{
+  return myCoords->Value(0);
+}
+
+double GeomData_Point2D::y() const
+{
+  return myCoords->Value(1);
+}
+
+GeomData_Point2D::GeomData_Point2D(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, 1);
+  }
+}
diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h
new file mode 100644 (file)
index 0000000..4b3d467
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        GeomData_Point2D.h
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomData_Point2D_HeaderFile
+#define GeomData_Point2D_HeaderFile
+
+#include "GeomData.h"
+#include "GeomDataAPI_Point2D.h"
+#include <TDataStd_RealArray.hxx>
+#include <TDF_Label.hxx>
+
+/**\class GeomData_Point2D
+ * \ingroup DataModel
+ * \brief Attribute that contains 2D point.
+ */
+
+class GeomData_Point2D : public GeomDataAPI_Point2D
+{
+  Handle_TDataStd_RealArray myCoords; ///< X and Y doubles as real array attribute [0; 1]
+public:
+  /// Defines the double value
+  GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY);
+
+  /// Returns the X double value
+  GEOMDATA_EXPORT virtual double x() const;
+  /// Returns the Y double value
+  GEOMDATA_EXPORT virtual double y() const;
+
+protected:
+  /// Initializes attributes
+  GEOMDATA_EXPORT GeomData_Point2D(TDF_Label& theLabel);
+
+  friend class Model_Data;
+};
+
+#endif
index 9f09481b043df5a5e7bc6b29d6610cb444b7afa3..389463212ab4c13582cec1d6efebc801b4056c81 100644 (file)
@@ -5,6 +5,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 SET(PROJECT_HEADERS
     GeomDataAPI.h
     GeomDataAPI_Point.h
+    GeomDataAPI_Dir.h
+    GeomDataAPI_Point2D.h
 )
 
 SET(CMAKE_SWIG_FLAGS "")
index f759848d9c7b03fe532fc88afe142f5018a00d03..455e0122e642146eaa073e5176c52bd11564da39 100644 (file)
@@ -3,6 +3,8 @@
 %{
   #include "GeomDataAPI.h"
   #include "GeomDataAPI_Point.h"
+  #include "GeomDataAPI_Dir.h"
+  #include "GeomDataAPI_Point2D.h"
   #include <boost/shared_ptr.hpp>
 %}
 
 // boost pointers
 %include <boost_shared_ptr.i>
 %shared_ptr(GeomDataAPI_Point)
+%shared_ptr(GeomDataAPI_Dir)
+%shared_ptr(GeomDataAPI_Point2D)
 
 // all supported interfaces
 %include "GeomDataAPI_Point.h"
+%include "GeomDataAPI_Dir.h"
+%include "GeomDataAPI_Point2D.h"
diff --git a/src/GeomDataAPI/GeomDataAPI_Dir.h b/src/GeomDataAPI/GeomDataAPI_Dir.h
new file mode 100644 (file)
index 0000000..90ab616
--- /dev/null
@@ -0,0 +1,41 @@
+// File:        GeomDataAPI_Dir.h
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomDataAPI_Dir_HeaderFile
+#define GeomDataAPI_Dir_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomDataAPI_Dir
+ * \ingroup DataModel
+ * \brief Attribute that contains 3D direction coordinates. 
+ */
+
+class GeomDataAPI_Dir : 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() const = 0;
+  /// Returns the Y double value
+  virtual double y() const = 0;
+  /// Returns the Z double value
+  virtual double z() const = 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_Dir()
+  {}
+};
+
+#endif
index d53271fd7e540f9a3da38903da7b8f9b2d049152..68f294e60fc8a9d4e967690d3fd917461e7b9828 100644 (file)
@@ -1,16 +1,16 @@
-// File:        GeomData_AttributeDouble.h
-// Created:     2 Apr 2014
+// File:        GeomDataAPI_Point.h
+// Created:     24 Apr 2014
 // Author:      Mikhail PONIKAROV
 
-#ifndef GeomData_AttributeDouble_HeaderFile
-#define GeomData_AttributeDouble_HeaderFile
+#ifndef GeomDataAPI_Point_HeaderFile
+#define GeomDataAPI_Point_HeaderFile
 
 #include "GeomDataAPI.h"
 #include <ModelAPI_Attribute.h>
 
-/**\class GeomData_AttributeDouble
+/**\class GeomDataAPI_Point
  * \ingroup DataModel
- * \brief Attribute that contains real value with double precision.
+ * \brief Attribute that contains 3D point coordinates. 
  */
 
 class GeomDataAPI_Point : public ModelAPI_Attribute
@@ -20,11 +20,11 @@ public:
   virtual void setValue(const double theX, const double theY, const double theZ) = 0;
 
   /// Returns the X double value
-  virtual double x() = 0;
+  virtual double x() const = 0;
   /// Returns the Y double value
-  virtual double y() = 0;
+  virtual double y() const = 0;
   /// Returns the Z double value
-  virtual double z() = 0;
+  virtual double z() const = 0;
 
   /// Returns the type of this class of attributes
   static inline std::string type() {return std::string("Point");}
diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h
new file mode 100644 (file)
index 0000000..bfc8094
--- /dev/null
@@ -0,0 +1,39 @@
+// File:        GeomDataAPI_Point2D.h
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomDataAPI_Point2D_HeaderFile
+#define GeomDataAPI_Point2D_HeaderFile
+
+#include "GeomDataAPI.h"
+#include <ModelAPI_Attribute.h>
+
+/**\class GeomDataAPI_Point2D
+ * \ingroup DataModel
+ * \brief Attribute that contains 2D point coordinates.
+ */
+
+class GeomDataAPI_Point2D : public ModelAPI_Attribute
+{
+public:
+  /// Defines the double value
+  virtual void setValue(const double theX, const double theY) = 0;
+
+  /// Returns the X double value
+  virtual double x() const = 0;
+  /// Returns the Y double value
+  virtual double y() const = 0;
+
+  /// Returns the type of this class of attributes
+  static inline std::string type() {return std::string("Point2D");}
+
+  /// 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_Point2D()
+  {}
+};
+
+#endif
index 24bee85be889d3455ad8ed342b4e6271a187f057..7b60ee48c26499f706c4a4876d1630aea4ceac53 100644 (file)
@@ -26,12 +26,14 @@ SET(PROJECT_SOURCES
 
 ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
 ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config)
+TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config GeomData)
 
 INCLUDE_DIRECTORIES(
   ../ModelAPI
   ../Events
   ../Config
+  ../GeomData
+  ../GeomDataAPI
   ${CAS_INCLUDE_DIRS}
 )
 
index 87c7be8672fda2dfa7b0a6b7c95ad461598d2bbc..121cd1902ce3bb63b3c025fd1c78c52a2585162a 100644 (file)
@@ -5,6 +5,8 @@
 #include <Model_Data.h>
 #include <Model_AttributeDocRef.h>
 #include <Model_AttributeDouble.h>
+#include <GeomData_Point.h>
+#include <GeomData_Point2D.h>
 #include <TDataStd_Name.hxx>
 
 using namespace std;
@@ -39,6 +41,10 @@ void Model_Data::addAttribute(string theID, string theAttrType)
     anAttr = new Model_AttributeDocRef(anAttrLab);
   else if (theAttrType == ModelAPI_AttributeDouble::type())
     anAttr = new Model_AttributeDouble(anAttrLab);
+  else if (theAttrType == GeomData_Point::type())
+    anAttr = new GeomData_Point(anAttrLab);
+  else if (theAttrType == GeomData_Point2D::type())
+    anAttr = new GeomData_Point2D(anAttrLab);
 
   if (anAttr)
     myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
@@ -75,3 +81,11 @@ boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string theID)
   }
   return aRes;
 }
+
+boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
+{
+  boost::shared_ptr<ModelAPI_Attribute> aResult;
+  if (myAttrs.find(theID) == myAttrs.end()) // no such attribute
+    return aResult;
+  return myAttrs[theID];
+}
index 5c3ffdf2ff66eb6105c92c829070792870712c36..647024e6d1290388f62ef50c583c0009741dc2cf 100644 (file)
@@ -43,6 +43,9 @@ public:
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
   /// Returns the attribute that contains real value with double precision
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID);
+  /// Returns the generic attribute by identifier
+  /// \param theID identifier of the attribute
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
 
   /// Initializes object by the attributes: must be called just after the object is created
   /// for each attribute of the object
index 1d4bf15e8b992db095952337e4cd4b04a4babea0..dfcdae495aefcf6f582c711b395af81c841384da 100644 (file)
@@ -12,7 +12,6 @@
  * \ingroup DataModel
  * \brief Generic attribute of the Object.
  */
-
 class MODELAPI_EXPORT ModelAPI_Attribute
 {
 public:
index 73fe3d7ded337819b4e5ca8dbfbb7aa69755ac32..077e75d2766110a4eafea99537fb1641afd967f1 100644 (file)
@@ -12,6 +12,7 @@
 class ModelAPI_AttributeDocRef;
 class ModelAPI_AttributeDouble;
 class ModelAPI_Document;
+class ModelAPI_Attribute;
 
 /**\class ModelAPI_Data
  * \ingroup DataModel
@@ -34,6 +35,10 @@ public:
   /// Returns the attribute that contains real value with double precision
   virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID) = 0;
 
+  /// Returns the generic attribute by identifier
+  /// \param theID identifier of the attribute
+  virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID) = 0;
+
   /// Initializes object by the attributes: must be called just after the object is created
   /// for each attribute of the object
   /// \param theID identifier of the attribute that can be referenced by this ID later
index 45abe7d5b1bd5e631848ec3971b2272e4b592e70..f8ce75a9284e361031176740707b573870993020 100644 (file)
@@ -47,6 +47,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI
                     ${CMAKE_SOURCE_DIR}/src/Events
                     ${CMAKE_SOURCE_DIR}/src/ModuleBase
                     ${CMAKE_SOURCE_DIR}/src/ModelAPI
+                    ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
                     ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
                     ${CMAKE_SOURCE_DIR}/src/SketchPlugin
                     ${CMAKE_SOURCE_DIR}/src/GeomAPI
index 8ce3b79589b82be90cfce5d7b7d2a8e33423ea04..c343503e2467bf22f60015430cd021df48d9c088 100644 (file)
@@ -8,6 +8,8 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
 
 #include <AIS_Shape.hxx>
 #include <AIS_ListOfInteractive.hxx>
@@ -57,11 +59,25 @@ void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Sh
   aPlane->coefficients(anA, aB, aC, aD);
 
   boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
-
+  /*
   aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
   aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
   aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
   aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
+  */
+  // temporary solution for main planes only
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+  anOrigin->setValue(0, 0, 0);
+  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+  aNormal->setValue(anA, aB, aC);
+  boost::shared_ptr<GeomDataAPI_Dir> aDirX = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+  aDirX->setValue(aB, aC, anA);
+  boost::shared_ptr<GeomDataAPI_Dir> aDirY = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+  aDirY->setValue(aC, anA, aB);
 
   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
   emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z());
index c075da118ed41a99d4bdb784058506ec5c116ec1..347fabe8818e0f69d364c882db8d78958406e317 100644 (file)
@@ -5,12 +5,14 @@ SET(PROJECT_HEADERS
     SketchPlugin_Feature.h
     SketchPlugin_Plugin.h
     SketchPlugin_Sketch.h
+    SketchPlugin_Line.h
 )
 
 SET(PROJECT_SOURCES
     SketchPlugin_Feature.cpp
     SketchPlugin_Plugin.cpp
     SketchPlugin_Sketch.cpp
+    SketchPlugin_Line.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -26,6 +28,7 @@ INCLUDE_DIRECTORIES(
   ../ModelAPI
   ../GeomAPI
   ../GeomAlgoAPI
+  ../GeomDataAPI
 )
 
 SET(XML_RESOURCES
index 2bb33c268c36be267526e0b38cfa6aca00640d30..26efd6e054c4fa6284ba73e02861afd75f7ad2fe 100644 (file)
@@ -7,9 +7,10 @@
 
 #include "SketchPlugin.h"
 #include <ModelAPI_Feature.h>
-
 #include <GeomAPI_Shape.h>
 
+class SketchPlugin_Sketch;
+
 /**\class SketchPlugin_Feature
  * \ingroup DataModel
  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
@@ -19,6 +20,7 @@ class SketchPlugin_Feature: public ModelAPI_Feature
 {
 public:
   /// Returns the sketch preview
+  /// \param theSketch the owner of this feature
   /// \return the built preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
 
diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp
new file mode 100644 (file)
index 0000000..5b5cf51
--- /dev/null
@@ -0,0 +1,47 @@
+// File:        SketchPlugin_Line.cxx
+// Created:     27 Mar 2014
+// Author:      Mikhail PONIKAROV
+
+#include "SketchPlugin_Line.h"
+#include "SketchPlugin_Sketch.h"
+#include <ModelAPI_Data.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomDataAPI_Point2D.h>
+
+using namespace std;
+
+// face of the square-face displayed for selection of general plane
+const double PLANE_SIZE = 200;
+
+SketchPlugin_Line::SketchPlugin_Line()
+{
+}
+
+void SketchPlugin_Line::initAttributes()
+{
+  data()->addAttribute(LINE_ATTR_START, GeomDataAPI_Point2D::type());
+  data()->addAttribute(LINE_ATTR_END, GeomDataAPI_Point2D::type());
+}
+
+void SketchPlugin_Line::execute() 
+{
+}
+
+const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Line::preview()
+{
+  boost::shared_ptr<SketchPlugin_Sketch> aSketch = SketchPlugin_Sketch::active();
+  // compute a start point in 3D view
+  boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_START));
+  boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+  // compute an end point in 3D view
+  boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_END));
+  boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+  // make linear edge
+  boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+  setPreview(anEdge);
+
+  return getPreview();
+}
diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h
new file mode 100644 (file)
index 0000000..9d0ae50
--- /dev/null
@@ -0,0 +1,45 @@
+// File:        SketchPlugin_Line.h
+// Created:     24 Apr 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef SketchPlugin_Line_HeaderFile
+#define SketchPlugin_Line_HeaderFile
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Feature.h>
+#include <list>
+
+/// Start 2D point of the line
+const std::string LINE_ATTR_START("StartPoint");
+/// End 2D point of the line
+const std::string LINE_ATTR_END("EndPoint");
+
+/**\class SketchPlugin_Line
+ * \ingroup DataModel
+ * \brief Feature for creation of the new part in PartSet.
+ */
+class SketchPlugin_Line: public SketchPlugin_Feature
+{
+public:
+  /// Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind() 
+  {static std::string MY_KIND = "SketchLine"; return MY_KIND;}
+
+  /// Returns to which group in the document must be added feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() 
+  {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
+
+  /// Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+ SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Returns the sketch preview
+  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+
+  /// Use plugin manager for features creation
+  SketchPlugin_Line();
+};
+
+#endif
index 878670ec209066a560bac09d903c460a74ada826..83480d9a8138d96c61632d511e7e4bb9cf9ab255 100644 (file)
@@ -4,12 +4,16 @@
 
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDouble.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
 using namespace std;
 
+/// the active sketch
+boost::shared_ptr<SketchPlugin_Sketch> MY_ACITVE_SKETCH;
+
 // face of the square-face displayed for selection of general plane
 const double PLANE_SIZE = 200;
 
@@ -19,10 +23,10 @@ SketchPlugin_Sketch::SketchPlugin_Sketch()
 
 void SketchPlugin_Sketch::initAttributes()
 {
-  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());
+  data()->addAttribute(SKETCH_ATTR_ORIGIN, GeomDataAPI_Point::type());
+  data()->addAttribute(SKETCH_ATTR_DIRX, GeomDataAPI_Dir::type());
+  data()->addAttribute(SKETCH_ATTR_DIRY, GeomDataAPI_Dir::type());
+  data()->addAttribute(SKETCH_ATTR_NORM, GeomDataAPI_Dir::type());
 }
 
 void SketchPlugin_Sketch::execute() 
@@ -42,6 +46,16 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
   return getPreview();
 }
 
+void SketchPlugin_Sketch::setActive(boost::shared_ptr<SketchPlugin_Sketch> theSketch)
+{
+  MY_ACITVE_SKETCH = theSketch;
+}
+
+boost::shared_ptr<SketchPlugin_Sketch> SketchPlugin_Sketch::active()
+{
+  return MY_ACITVE_SKETCH;
+}
+
 void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
                                    std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
 {
@@ -51,3 +65,18 @@ void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
     GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
   theShapes.push_back(aFace);
 }
+
+boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
+{
+  boost::shared_ptr<GeomDataAPI_Point> aC = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aX = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRX));
+  boost::shared_ptr<GeomDataAPI_Dir> aY = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRY));
+
+  return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(
+    aC->x() + aX->x() * theX + aY->x() * theY, 
+    aC->y() + aX->y() * theX + aY->y() * theY,
+    aC->z() + aX->z() * theX + aY->z() * theY));
+}
index ec81fe62e6fc0fe82744163617d108a253e193c8..3c6181200faf5747bc70f4911c8da25dde1ac241 100644 (file)
@@ -7,16 +7,17 @@
 
 #include "SketchPlugin.h"
 #include <SketchPlugin_Feature.h>
+#include <GeomAPI_Pnt.h>
 #include <list>
 
-/// 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");
+/// Origin point of the sketcher in 3D space
+const std::string SKETCH_ATTR_ORIGIN("Origin");
+/// Vector X inside of the sketch plane
+const std::string SKETCH_ATTR_DIRX("DirX");
+/// Vector Y inside of the sketch plane
+const std::string SKETCH_ATTR_DIRY("DirY");
+/// Vector Z, normal to the sketch plane
+const std::string SKETCH_ATTR_NORM("Norm");
 
 /**\class SketchPlugin_Sketch
  * \ingroup DataModel
@@ -42,6 +43,18 @@ public:
   /// Returns the sketch preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
 
+  /// Sets the sketch as active. All features and features previews 
+  /// will be connected to this sketch.
+  SKETCHPLUGIN_EXPORT static void setActive(boost::shared_ptr<SketchPlugin_Sketch> theSketch);
+
+  /// Returns the currently active sketch. All features and features previews 
+  /// will be connected to this sketch.
+  SKETCHPLUGIN_EXPORT static boost::shared_ptr<SketchPlugin_Sketch> active();
+
+  /// Converts a 2D sketch space point into point in 3D space
+  SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
+    const double theX, const double theY);
+
   /// Use plugin manager for features creation
   SketchPlugin_Sketch();
 protected: