]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authornds <natalia.donis@opencascade.com>
Wed, 5 Nov 2014 16:32:33 +0000 (19:32 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 5 Nov 2014 16:32:33 +0000 (19:32 +0300)
src/GeomAPI/GeomAPI_AISObject.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp
src/SketchPlugin/SketchPlugin_ConstraintRigid.h
src/SketchPlugin/SketchPlugin_Plugin.cpp

index de00d5a436b33a88144ec9e07bca6a0b11ce77f5..ec84c8c3460660c9974f0f190773700aff4f613e 100644 (file)
@@ -15,6 +15,7 @@
 #include <Geom_Plane.hxx>
 #include <TopoDS_Shape.hxx>
 #include <Quantity_NameOfColor.hxx>
+#include <BRepBndLib.hxx>
 
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_LengthDimension.hxx>
@@ -226,20 +227,32 @@ void GeomAPI_AISObject::createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
 {
   Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl<gp_Pln>());
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  Handle(AIS_FixRelation) aFixPrs;
   if (anAIS.IsNull()) {
-    Handle(AIS_FixRelation) aFixPrs = 
-      new AIS_FixRelation(theShape->impl<TopoDS_Shape>(), aPlane);
+    aFixPrs = new AIS_FixRelation(aShape, aPlane);
 
     setImpl(new Handle(AIS_InteractiveObject)(aFixPrs));
   } else {
-    Handle(AIS_PerpendicularRelation) aFixPrs = 
-      Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+    aFixPrs = Handle(AIS_FixRelation)::DownCast(anAIS);
     if (!aFixPrs.IsNull()) {
-      aFixPrs->SetFirstShape(theShape->impl<TopoDS_Shape>());
+      aFixPrs->SetFirstShape(aShape);
       aFixPrs->SetPlane(aPlane);
       aFixPrs->Redisplay(Standard_True);
     }
   }
+  if (!aFixPrs.IsNull()) {
+    Bnd_Box aBox;
+    BRepBndLib::Add(aShape, aBox);
+    double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax;
+    aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+    gp_Pnt aXYZ1(aXmin, aXmax, aYmin);
+    gp_Pnt aXYZ2(aXmax, aYmax, aZmax);
+    double aDist = aXYZ1.Distance(aXYZ2);
+    if (aDist > Precision::Confusion()) {
+      aFixPrs->SetArrowSize(aDist/8.);
+    }
+  }
 }
 
 
index bd5e54e707b51b445aeeaad5f50eb4cac305047b..4a53eb0438d730b3671190346966dee17abb413d 100644 (file)
@@ -187,12 +187,27 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
     ObjectPtr aObject = aObjects.first();
     if ((!mySelectedObject) && (!aObject))
       return;
-    if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
-      return;
+
     // Check that the selected object is result (others can not be accepted)
     ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
     if (!aRes)
       return;
+
+    if (myFeature) {
+      // We can not select a result of our feature
+      const std::list<boost::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
+      std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+      for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+        if ((*aIt) == aRes)
+          return;
+      }
+    }
+    // Check that object belongs to active document or PartSet
+    DocumentPtr aDoc = aRes->document();
+    SessionPtr aMgr = ModelAPI_Session::get();
+    if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+      return;
+
     // Check that the result has a shape
     GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
     if (!aShape)
@@ -218,6 +233,7 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
         return;
     }
     setObject(aObject, aShape);
+    //activateSelection(false);
     emit focusOutWidget(this);
   }
 }
@@ -225,8 +241,6 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape)
 {
-  if (mySelectedObject == theObj)
-    return;
   mySelectedObject = theObj;
   myShape = theShape;
   if (mySelectedObject) {
@@ -245,20 +259,6 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_p
 bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
 {
   ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
-  if (myFeature) {
-    // We can not select a result of our feature
-    const std::list<boost::shared_ptr<ModelAPI_Result>>& aRes = myFeature->results();
-    std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
-    for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
-      if ((*aIt) == aResult)
-        return false;
-    }
-  }
-  // Check that object belongs to active document or PartSet
-  DocumentPtr aDoc = aResult->document();
-  SessionPtr aMgr = ModelAPI_Session::get();
-  if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
-    return false;
 
   // Check that the shape of necessary type
   boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
index 3916b3d0a0245fa9150f2a89323df5a18e135961..d2c0d9de888270eb9e21938692d81e911602edaa 100644 (file)
@@ -264,6 +264,10 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
+}
+
+void PartSet_Module::onSketchLaunched()
+{
   xWorkshop()->actionsMgr()->update();
   // Set working plane
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
@@ -444,6 +448,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
               SLOT(onPlaneSelected(double, double, double)));
       connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
+      connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
     }
   }
 
index f5851100ce749aa309c4dd6dc8367c7d74f60aee..a3a188ad0347ff9a10f376b7bc06d3f382f84928 100644 (file)
@@ -107,6 +107,9 @@ Q_OBJECT
   /// \param the attribute of the feature
   void onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute);
 
+  /// Called when sketch is launched
+  void onSketchLaunched();
+
 protected slots:
   /// Called on selection changed event
   virtual void onSelectionChanged();
index 2a39d0924745159db636cb5e8db4645490349e00..5efa67ae3bab39ce884a273b7ff4d940e3f05cf1 100644 (file)
@@ -104,13 +104,15 @@ void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelecti
     // We have to select a plane before any operation
     TopoDS_Shape aShape = aPrs.shape();
     if (!aShape.IsNull()) {
-      setSketchPlane(aShape);
+      boost::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
+      flushUpdated();
+      emit featureConstructed(feature(), FM_Hide);
       // If selection is not a sketcher presentation then it has to be stored as 
       // External shape
       if (feature() != aPrs.object()) {
-        boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
-          boost::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
-        DataPtr aData = aSketch->data();
+        //boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
+        //  boost::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
+        DataPtr aData = feature()->data();
         AttributeSelectionPtr aSelAttr = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>
           (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
@@ -122,7 +124,11 @@ void PartSet_OperationSketch::selectionChanged(ModuleBase_ISelection* theSelecti
             aSelAttr->setValue(aRes, aShapePtr);
           }
         }
+      } else {
+        // Turn viewer to the plane
+        emit planeSelected(aDir->x(), aDir->y(), aDir->z());
       }
+      emit launchSketch();
     }
   }
 }
@@ -229,10 +235,10 @@ bool PartSet_OperationSketch::hasSketchPlane() const
   return aHasPlane;
 }
 
-void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
+boost::shared_ptr<GeomAPI_Dir> PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
 {
   if (theShape.IsNull())
-    return;
+    return boost::shared_ptr<GeomAPI_Dir>();
 
   // get selected shape
   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
@@ -273,11 +279,7 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
       aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
   aDirY->setValue(aYDir);
   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
-
-  flushUpdated();
-
-  emit featureConstructed(feature(), FM_Hide);
-  emit planeSelected(aDir->x(), aDir->y(), aDir->z());
+  return aDir;
 }
 
 
index 47601096f7b1af293facbb3c9fd3e2daf98aeb70..eb3fa84f4a182368c025a3d64b05881d1ea6ecfa 100644 (file)
@@ -86,7 +86,8 @@ Q_OBJECT
 
   /// Set the plane to the current sketch
   /// \param theShape the shape
-  void setSketchPlane(const TopoDS_Shape& theShape);
+  /// \return selected direction
+  boost::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
   
   /// Called on selection changed when the operation is active
   virtual void selectionChanged(ModuleBase_ISelection* theSelection);
@@ -104,6 +105,9 @@ signals:
   // signal about the viewer fit all perform
   void fitAllView();
 
+  /// Signal to define sketch mode
+  void launchSketch();
+
  protected:
   /// Virtual method called when operation started (see start() method for more description)
   /// Default impl calls corresponding slot and commits immediately.
index 1b02335dffd69fe730f98ee3c8f62e476ecfb920..847ecfc86238c86c59afe562b3d7b1adb2151727 100644 (file)
@@ -5,6 +5,7 @@
 #include "SketchPlugin_ConstraintRigid.h"
 
 #include <ModelAPI_ResultConstruction.h>
+#include <Config_PropManager.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAlgoAPI_PointBuilder.h>
@@ -60,9 +61,9 @@ AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious
   anAIS->createFixed(aShape, aPlane);
 
   // Set color from preferences
-  //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
-  //                                                  PERPENDICULAR_COLOR);
-  //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+  std::vector<int> aRGB = Config_PropManager::color("Visualization", "fixing_color",
+                                                    FIXING_COLOR);
+  anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
 
   return anAIS;
 }
\ No newline at end of file
index 8816ea4b632d9658bb38748db79b24e0a3e3fade..7dc6ef8e9771ed44ca74e2959e066c0b9053a798 100644 (file)
@@ -10,6 +10,8 @@
 #include <SketchPlugin_Sketch.h>
 #include <list>
 
+#define FIXING_COLOR "#ffff00"
+
 /** \class SketchPlugin_ConstraintRigid
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint which defines immovable object
index cf3cf283b9e6780efd3f882697d3a9c4182b00ef..07768577649ec2cd8d3a8c974c111350f987817e 100644 (file)
@@ -58,6 +58,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                                    Config_Prop::Color, LENGTH_COLOR);
   Config_PropManager::registerProp("Visualization", "radius_color", "Radius color",
                                    Config_Prop::Color, RADIUS_COLOR);
+  Config_PropManager::registerProp("Visualization", "fixing_color", "Fixing color",
+                                   Config_Prop::Color, FIXING_COLOR);
 }
 
 FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)