Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
index 850058e8c1d438da7edb4a59c41fcac9d05ded49..81ead9d7ded55fffa4dd660608b21e10f8e138dd 100644 (file)
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_SketchBuilder.h>
 
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <Quantity_NameOfColor.hxx>
+
+const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
+const int SKETCH_WIDTH = 4; /// the plane edge width
+
 using namespace std;
 
 // face of the square-face displayed for selection of general plane
@@ -37,6 +45,8 @@ void SketchPlugin_Sketch::execute()
   boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
     boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(SKETCH_ATTR_FEATURES));
 
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
   boost::shared_ptr<GeomDataAPI_Dir> aDirX = 
     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_DIRX));
   boost::shared_ptr<GeomDataAPI_Dir> aDirY = 
@@ -62,7 +72,7 @@ void SketchPlugin_Sketch::execute()
 
   std::list< boost::shared_ptr<GeomAPI_Shape> > aLoops;
   std::list< boost::shared_ptr<GeomAPI_Shape> > aWires;
-  GeomAlgoAPI_SketchBuilder::createFaces(aDirX->dir(), aDirY->dir(), aNorm->dir(),
+  GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
                                          aFeaturesPreview, aLoops, aWires);
 
   aLoops.insert(aLoops.end(), aWires.begin(), aWires.end());
@@ -70,6 +80,16 @@ void SketchPlugin_Sketch::execute()
   data()->store(aCompound);
 }
 
+Handle(AIS_InteractiveObject) SketchPlugin_Sketch::getAISShape(Handle(AIS_InteractiveObject) thePrevious)
+{
+  Handle(AIS_InteractiveObject) anAIS = SketchPlugin_Feature::getAISShape(thePrevious);
+  Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+  aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
+  aShapeAIS->SetWidth(SKETCH_WIDTH);
+  aShapeAIS->Redisplay();
+  return anAIS;
+}
+
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
 {
   if (isPlaneSet()) {
@@ -125,3 +145,16 @@ bool SketchPlugin_Sketch::isPlaneSet()
 
   return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
 }
+
+boost::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
+{
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aNorm = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+
+  if (!anOrigin || !aNorm)
+    return boost::shared_ptr<GeomAPI_Pln>();
+
+  return boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+}