Salome HOME
Removed not used function SimpleAISobject
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 11 Dec 2014 16:56:46 +0000 (19:56 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 11 Dec 2014 16:56:46 +0000 (19:56 +0300)
Provided customization of sketch objects presentations

src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAPI/GeomAPI_ICustomPrs.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_Feature.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Point.h
src/XGUI/XGUI_Displayer.cpp

index e08c67fc1fcece5e8c156fc1b05f02d923bff8d2..eec0e4d2c7529624f826adaf78ed1a25c0dd21d2 100644 (file)
@@ -27,6 +27,7 @@ SET(PROJECT_HEADERS
     GeomAPI_IPresentable.h
     GeomAPI_Curve.h 
     GeomAPI_DataMapOfShapeShape.h
+       GeomAPI_ICustomPrs.h
 )
 
 SET(PROJECT_SOURCES
index f1534e2afae88490f226be39e09c5b313f98cc5e..1e6566c093c093a03006127fe66049d5af3f6364 100644 (file)
@@ -26,6 +26,7 @@
 #include <AIS_RadiusDimension.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_FixRelation.hxx>
+#include <Prs3d_PointAspect.hxx>
 
 const double tolerance = 1e-7;
 
@@ -296,3 +297,31 @@ bool GeomAPI_AISObject::empty() const
   return false;
 }
 
+int GeomAPI_AISObject::getShapeType() const
+{
+  Handle(AIS_InteractiveObject) anAIS = const_cast<GeomAPI_AISObject*>(this)
+      ->impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!aAISShape.IsNull()) {
+      return aAISShape->Shape().ShapeType();
+    }
+  }
+  return -1;
+}
+
+void GeomAPI_AISObject::setPointMarker(int theType, double theScale)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
+    if (aDrawer->HasPointAspect()) {
+      Handle(Prs3d_PointAspect) aPA = aDrawer->PointAspect();
+      aPA->SetTypeOfMarker((Aspect_TypeOfMarker)theType);
+      aPA->SetScale(theScale);
+    } else {
+      Quantity_NameOfColor aCol = Quantity_NOC_YELLOW;
+      aDrawer->SetPointAspect(new Prs3d_PointAspect((Aspect_TypeOfMarker)theType, aCol, theScale));
+    }
+  }
+}
index 48e3d6fa0144b48f4488505698462c55f08a8192..1477c5a139634265678b7b0ff10b4ee31f1da515 100644 (file)
@@ -95,6 +95,14 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
 
   /// \brief Checks if the object is empty
   bool empty() const;
+
+  /// Return shape type according to TopAbs_ShapeEnum if the AIS is AIS_Shape
+  /// Otherwise returns -1
+  int getShapeType() const;
+
+  /// Sets marker type for vertex.
+  /// The type has to be defined according to Acpect_TypeOfMarker
+  void setPointMarker(int theType, double theScale);
 };
 
 //! Pointer on attribute object
diff --git a/src/GeomAPI/GeomAPI_ICustomPrs.h b/src/GeomAPI/GeomAPI_ICustomPrs.h
new file mode 100644 (file)
index 0000000..c398a33
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_ICustomPrs.hxx
+// Created:     11 Dec 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef GeomAPI_ICustomPrs_H
+#define GeomAPI_ICustomPrs_H
+
+#include "GeomAPI_AISObject.h"
+
+/**
+* Interface of a class which can provide specific customization of
+* object presentation
+*/ 
+class GeomAPI_ICustomPrs
+{
+public:
+  virtual void customisePresentation(AISObjectPtr thePrs) = 0;
+};
+
+typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
+
+#endif
\ No newline at end of file
index ab56e8ed8afb3dd086d2c0174c9935d9cc7ae8e7..76bac7887bf111ab1f23b7b131714f4bc344820d 100644 (file)
@@ -16,7 +16,7 @@
  * \ingroup DataModel
  * \brief Feature for creation of the new circle in PartSet.
  */
-class SketchPlugin_Circle : public SketchPlugin_Feature  //, public GeomAPI_IPresentable
+class SketchPlugin_Circle : public SketchPlugin_Feature 
 {
  public:
   /// Circle feature kind
@@ -56,12 +56,6 @@ class SketchPlugin_Circle : public SketchPlugin_Feature  //, public GeomAPI_IPre
   /// Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Returns the AIS preview
-  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious)
-  {
-    return simpleAISObject(firstResult(), thePrevious);
-  }
-
   /// Adds sub-feature of the higher level feature (sub-element of the sketch)
   /// \param theFeature sub-feature
   SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
index 9916b78e5e13d90937a050cda1770ee77fdc7255..dcd2f9847d14220cffbb693f67aed8448fb87e0d 100644 (file)
@@ -31,19 +31,13 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
   return mySketch;
 }
 
-AISObjectPtr SketchPlugin_Feature::simpleAISObject(std::shared_ptr<ModelAPI_Result> theRes,
-                                                   AISObjectPtr thePrevious)
-{
-  std::shared_ptr<ModelAPI_ResultConstruction> aConstr = std::dynamic_pointer_cast<
-      ModelAPI_ResultConstruction>(theRes);
-
-  std::shared_ptr<GeomAPI_Shape> aPreview;
-  if (aConstr)
-    aPreview = aConstr->shape();
 
-  AISObjectPtr aResult = thePrevious;
-  if (!aResult)
-    aResult = AISObjectPtr(new GeomAPI_AISObject());
-  aResult->createShape(aPreview);
-  return aResult;
-}
+void SketchPlugin_Feature::customisePresentation(AISObjectPtr thePrs)
+{
+  // if this is an edge
+  if (thePrs->getShapeType() == 6)
+    thePrs->setWidth(3);
+  // if this is a vertex
+  else if (thePrs->getShapeType() == 7)
+    thePrs->setPointMarker(6, 2.);
+}
\ No newline at end of file
index 01b9d88eecf788dd89f6f2ec9a7b858ea32cd17f..7ca0eb6d36d6f0f995d0e32ca7c8d0c53073b2cc 100644 (file)
@@ -13,6 +13,7 @@
 #include <GeomAPI_AISObject.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <GeomAPI_ICustomPrs.h>
 
 class SketchPlugin_Sketch;
 class GeomAPI_Pnt2d;
@@ -23,13 +24,9 @@ class Handle_AIS_InteractiveObject;
  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
  * an interface to create the sketch feature preview.
  */
-class SketchPlugin_Feature : public ModelAPI_Feature
+class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
 {
  public:
-  /// Simple creation of interactive object by the result of the object
-  static AISObjectPtr simpleAISObject(std::shared_ptr<ModelAPI_Result> theRes,
-                                      AISObjectPtr thePrevious);
-
   /// Reference to the external edge or vertex as a AttributeSelection
   inline static const std::string& EXTERNAL_ID()
   {
@@ -66,6 +63,9 @@ class SketchPlugin_Feature : public ModelAPI_Feature
     return false;
   }
 
+  /// Customize presentation of the feature
+  virtual void customisePresentation(AISObjectPtr thePrs);
+
   /// Returns the sketch of this feature
   SketchPlugin_Sketch* sketch();
 protected:
index e31dfb59d02c13fc80236d88bfcdb8d81257a932..50d8f438f5072358de6535d2d05472f8f110e230 100644 (file)
@@ -116,3 +116,4 @@ void SketchPlugin_Line::attributeChanged(const std::string& theID) {
     }
   }
 }
+
index 46161cf74235b87300967783a5611713f2675c41..be5fadaad66033f31cbf06f746750f9cfc69f55c 100644 (file)
@@ -54,12 +54,6 @@ class SketchPlugin_Line : public SketchPlugin_Feature
   /// Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Returns the AIS preview
-  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious)
-  {
-    return simpleAISObject(firstResult(), thePrevious);
-  }
-
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
index 4d2845c1c0958eb1c5bb9fcca2cf1541cece47f2..a60f9bebab70a1e73c8619b6ebda4125aaca165e 100644 (file)
@@ -47,12 +47,6 @@ class SketchPlugin_Point : public SketchPlugin_Feature
   /// Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Returns the AIS preview
-  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious)
-  {
-    return simpleAISObject(firstResult(), thePrevious);
-  }
-
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
index a0fe6a50fcc1fb01432787b5f3037517c0d59f41..3a530c2f4aff8b6249612d07499c3fe9ec22a149 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_IPresentable.h>
+#include <GeomAPI_ICustomPrs.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_LocalContext.hxx>
@@ -87,6 +88,12 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!anAISIO.IsNull()) {
     myResult2AISObjectMap[theObject] = theAIS;
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature.get() != NULL) {
+      GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+      if (aCustPrs.get() != NULL)
+        aCustPrs->customisePresentation(theAIS);
+    }
     aContext->Display(anAISIO, false);
     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, isUpdateViewer);
     if (aContext->HasOpenedContext()) {