Salome HOME
Add ellipse data type
authorvsv <vsv@opencascade.com>
Tue, 25 Apr 2017 12:50:25 +0000 (15:50 +0300)
committervsv <vsv@opencascade.com>
Tue, 25 Apr 2017 12:50:25 +0000 (15:50 +0300)
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Ax2.h
src/GeomAPI/GeomAPI_Circ.h
src/GeomAPI/GeomAPI_Dir.h
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/GeomAPI/GeomAPI_Ellipse.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Ellipse.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Pnt.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h

index 3332171b0ca1317d620fe2ad888a292deb926806..d76e17b78e54fb3e3dd691997713f4c0d980a085 100644 (file)
@@ -38,6 +38,7 @@ SET(PROJECT_HEADERS
     GeomAPI_Trsf.h
     GeomAPI_Angle2d.h
     GeomAPI_Wire.h
+       GeomAPI_Ellipse.h
 )
 
 SET(PROJECT_SOURCES
@@ -72,6 +73,7 @@ SET(PROJECT_SOURCES
     GeomAPI_Trsf.cpp
     GeomAPI_Angle2d.cpp
     GeomAPI_Wire.cpp
+       GeomAPI_Ellipse.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 1ad5bcc1a90f9f4bd7f10a6c33c56c9a69a4c9df..2a740d114bee65e03ca60d204a9f4db641048668 100644 (file)
@@ -56,4 +56,7 @@ public:
   std::shared_ptr<GeomAPI_Dir> dir() const;
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Ax2> GeomAx2Ptr;
+
 #endif
index 625ca3895b0a677dc6d652a611e6bb383d3f479b..686b42edee5bb5d33e634e95fc266eac21af7b9c 100644 (file)
@@ -23,7 +23,8 @@ class GeomAPI_Circ : public GeomAPI_Interface
 {
  public:
 
-  /** \brief Constructs a circle of radius Radius, where theAx2 locates the circle and defines its orientation in 3D space such that:\n
+  /** \brief Constructs a circle of radius Radius, where theAx2 locates
+   *  the circle and defines its orientation in 3D space such that:\n
    *  - the center of the circle is the origin of theAx2;\n
    *  - the origin, "X Direction" and "Y Direction" of theAx2 define the plane of the circle;\n
    *  - theAx2 is the local coordinate system of the circle.\n
index 9231e58f785ac33bcf55dcb664ec3da7b8411444..542f7a5f92b24e5e0bbbec57889df4f5225702a5 100644 (file)
@@ -64,5 +64,8 @@ class GeomAPI_Dir : public GeomAPI_Interface
 
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Dir> GeomDirPtr;
+
 #endif
 
index 0ce6340051477195687fb07664200515d6c41ea5..925e34ec7bea3466f6665a5505f3d8f0378a1bbf 100644 (file)
@@ -10,6 +10,8 @@
 #include<GeomAPI_Circ.h>
 #include<GeomAPI_Dir.h>
 #include<GeomAPI_Lin.h>
+#include<GeomAPI_Ax2.h>
+#include<GeomAPI_Ellipse.h>
 
 #include <BRepAdaptor_Curve.hxx>
 
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Circle.hxx>
+#include <Geom_Ellipse.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <gp_Ax1.hxx>
 #include <gp_Pln.hxx>
+#include <gp_Elips.hxx>
 
 #include <GCPnts_AbscissaPoint.hxx>
 
@@ -82,6 +86,16 @@ bool GeomAPI_Edge::isArc() const
   return false;
 }
 
+bool GeomAPI_Edge::isEllipse() const
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+  if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse)))
+    return true;
+  return false;
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
@@ -102,14 +116,14 @@ std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
 }
 
-std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
+std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
   double aFirst, aLast;
   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
-  if (aCurve) {
+  if (!aCurve.IsNull()) {
     Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
-    if (aCirc) {
+    if (!aCirc.IsNull()) {
       gp_Pnt aLoc = aCirc->Location();
       std::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
       gp_Dir anAxis = aCirc->Axis().Direction();
@@ -120,7 +134,24 @@ std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
   return std::shared_ptr<GeomAPI_Circ>(); // not circle
 }
 
-std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line()
+std::shared_ptr<GeomAPI_Ellipse> GeomAPI_Edge::ellipse() const
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+  if (!aCurve.IsNull()) {
+    Handle(Geom_Ellipse) aElips = Handle(Geom_Ellipse)::DownCast(aCurve);
+    if (!aElips.IsNull()) {
+      gp_Elips aGpElips = aElips->Elips();
+      std::shared_ptr<GeomAPI_Ellipse> aEllipse(new GeomAPI_Ellipse());
+      aEllipse->setImpl(new gp_Elips(aGpElips));
+      return aEllipse;
+    }
+  }
+  return std::shared_ptr<GeomAPI_Ellipse>(); // not elipse
+}
+
+std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
   double aFirst, aLast;
index 83eaad634607b56497c191ea5914512ce18ce2f9..05ac002f1decb9b11ccb6d32d7729d1cbb553bb2 100644 (file)
@@ -13,6 +13,7 @@ class GeomAPI_Pln;
 class GeomAPI_Pnt;
 class GeomAPI_Circ;
 class GeomAPI_Lin;
+class GeomAPI_Ellipse;
 
 /**\class GeomAPI_Edge
 * \ingroup DataModel
@@ -42,6 +43,10 @@ public:
   GEOMAPI_EXPORT
   bool isArc() const;
 
+  /// Verifies that the edge is an arc of circle
+  GEOMAPI_EXPORT
+  bool isEllipse() const;
+
   /// Returns the first vertex coordinates of the edge
   GEOMAPI_EXPORT
   std::shared_ptr<GeomAPI_Pnt> firstPoint();
@@ -52,11 +57,15 @@ public:
 
   /// Returns a circle if edge is based on the circle curve
   GEOMAPI_EXPORT
-  std::shared_ptr<GeomAPI_Circ> circle();
+  std::shared_ptr<GeomAPI_Circ> circle() const;
+
+  /// Returns an ellipse if edge is based on the ellipse curve
+  GEOMAPI_EXPORT
+  std::shared_ptr<GeomAPI_Ellipse> ellipse() const;
 
   /// Returns a line if edge is based on the linear curve
   GEOMAPI_EXPORT
-  std::shared_ptr<GeomAPI_Lin> line();
+  std::shared_ptr<GeomAPI_Lin> line() const;
 
   /// Returns true if the current edge is geometrically equal to the given edge
   GEOMAPI_EXPORT
@@ -75,5 +84,8 @@ public:
   double length() const;
 };
 
+//! Pointer on attribute object
+typedef std::shared_ptr<GeomAPI_Edge> GeomEdgePtr;
+
 #endif
 
diff --git a/src/GeomAPI/GeomAPI_Ellipse.cpp b/src/GeomAPI/GeomAPI_Ellipse.cpp
new file mode 100644 (file)
index 0000000..1eae644
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_Ellipse.cpp
+// Created:     25 April 2017
+// Author:      Vitaly Smetannikov
+
+#include "GeomAPI_Ellipse.h"
+#include "GeomAPI_Ax2.h"
+#include "GeomAPI_Pnt.h"
+
+#include <gp_Elips.hxx>
+
+#define MY_ELIPS implPtr<gp_Elips>()
+
+GeomAPI_Ellipse::GeomAPI_Ellipse(const std::shared_ptr<GeomAPI_Ax2>& theAx2,
+                                 double theMajorRadius, double theMinorRadius)
+: GeomAPI_Interface(new gp_Elips(theAx2->impl<gp_Ax2>(), theMajorRadius, theMinorRadius))
+{
+}
+
+GeomPointPtr GeomAPI_Ellipse::firstFocus() const
+{
+  const gp_Pnt& aFirst = MY_ELIPS->Focus1();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aFirst.X(), aFirst.Y(), aFirst.Z()));
+}
+
+GeomPointPtr GeomAPI_Ellipse::secondFocus() const
+{
+  const gp_Pnt& aSecond = MY_ELIPS->Focus2();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSecond.X(), aSecond.Y(), aSecond.Z()));
+}
+
+double GeomAPI_Ellipse::minorRadius() const
+{
+  return MY_ELIPS->MinorRadius();
+}
+
+double GeomAPI_Ellipse::majorRadius() const
+{
+  return MY_ELIPS->MajorRadius();
+}
diff --git a/src/GeomAPI/GeomAPI_Ellipse.h b/src/GeomAPI/GeomAPI_Ellipse.h
new file mode 100644 (file)
index 0000000..a855e18
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_Ellipse.h
+// Created:     25 April 2017
+// Author:      Vitaly Smetannikov
+
+#ifndef GeomAPI_Ellipse_H_
+#define GeomAPI_Ellipse_H_
+
+#include <GeomAPI_Interface.h>
+#include <memory>
+
+class GeomAPI_Pnt;
+class GeomAPI_Ax2;
+
+
+/**\class GeomAPI_Ellipse
+ * \ingroup DataModel
+ * \brief Ellipse in 3D
+ */
+class GeomAPI_Ellipse : public GeomAPI_Interface
+{
+public:
+
+  /// \brief Constructs an epty ellipse
+  GEOMAPI_EXPORT GeomAPI_Ellipse() : GeomAPI_Interface() {}
+
+  /** \brief Constructs an ellipse with major and minor radiuses,
+   *  where theAx2 locates the ellipse and defines its orientation in 3D space such that:\n
+   *  - the center of the circle is the origin of theAx2;\n
+   *  - the origin, "X Direction" and "Y Direction" of theAx2 define the plane of the circle;\n
+   *  - theAx2 is the local coordinate system of the circle.\n
+   *    Note: It is possible to create a circle where Radius is equal to 0.0. raised if Radius < 0.
+   */
+  GEOMAPI_EXPORT GeomAPI_Ellipse(const std::shared_ptr<GeomAPI_Ax2>& theAx2,
+                                 double theMajorRadius, double theMinorRadius);
+
+  /// Returns first center of the ellipse
+  GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Pnt> firstFocus() const;
+
+  /// Returns second center of the ellipse
+  GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Pnt> secondFocus() const;
+
+  /// Returns minor radius of the ellipse
+  GEOMAPI_EXPORT double minorRadius() const;
+
+  /// Returns major radius of the ellipse
+  GEOMAPI_EXPORT double majorRadius() const;
+
+};
+
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Ellipse> GeomEllipsePtr;
+
+#endif
index 137b6f72958b0c50074d8eae3ae9e2b55c9390f5..6f9ee1df7d65a58c3c1324b3e71a9d8c9fd177e0 100644 (file)
@@ -77,4 +77,7 @@ class GeomAPI_Pnt : public GeomAPI_Interface
   void translate(const std::shared_ptr<GeomAPI_Dir>& theDir, double theDist);
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Pnt> GeomPointPtr;
+
 #endif
index 473f6e5d6168ae6e3dc86b236997c9ff051e84d7..b3a05a35c0db0141777a835669dfe9c108d36774 100644 (file)
@@ -34,6 +34,8 @@
 #include <GeomDataAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
 #include <GeomAPI_Face.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <SketchPlugin_Sketch.h>
 #include <SketcherPrs_Tools.h>
@@ -526,6 +528,9 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
     QIntList aModes;
     std::shared_ptr<GeomAPI_Pln> aPlane = plane();
     if (aPlane.get()) {
+      //QList<std::shared_ptr<ModuleBase_ViewerPrs>> aEdges = findCircularEdgesInPlane();
+      //foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aEdges) {
+      //}
       myWorkshop->module()->activeSelectionModes(aModes);
     }
     else {
@@ -605,3 +610,47 @@ void PartSet_WidgetSketchLabel::onSetPlaneView()
       aModule->onViewTransformed();
   }
 }
+
+
+//******************************************************
+QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCircularEdgesInPlane()
+{
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> aResult;
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  QObjectPtrList aDispObjects = aDisplayer->displayedObjects();
+
+  std::shared_ptr<GeomAPI_Pln> aPlane = plane();
+  foreach(ObjectPtr aObj, aDispObjects) {
+    ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+    if (aResObj.get()) {
+      GeomShapePtr aShape = aResObj->shape();
+      if (aShape.get()) {
+        GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE);
+        for(; aExplorer.more(); aExplorer.next()) {
+          GeomShapePtr aEdgeShape = aExplorer.current();
+          GeomAPI_Edge anEdge(aEdgeShape);
+          if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) &&
+               anEdge.isInPlane(aPlane)) {
+            bool isContains = false;
+            // Check that edge is not used.
+            // It is possible that the same edge will be taken from different faces
+            foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aResult) {
+              GeomAPI_Edge aUsedEdge(aPrs->shape());
+              if (aUsedEdge.isEqual(aEdgeShape)) {
+                isContains = true;
+                break;
+              }
+            }
+            if (!isContains) {
+              std::shared_ptr<ModuleBase_ViewerPrs>
+                aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape));
+              aResult.append(aPrs);
+            }
+          }
+        }
+      }
+    }
+  }
+  return aResult;
+}
index 7e0a1c73e88798100ab9ca1ee6acc62ac38ac7c7..6a3aa446284f2e7f0bba73d2f0c42d7582903232 100644 (file)
@@ -178,6 +178,13 @@ protected:
   /// \param thePlane a plane
   std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
 
+  /**
+  * Returns list of presentations which have displayed shapes with circular edges
+  * (circles, arcs) which are in pane of of the given sketch
+  * \param theSketch - the sketch
+  */
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> findCircularEdgesInPlane();
+
 private:
   /// class to show/hide preview planes
   PartSet_PreviewPlanes* myPreviewPlanes;