]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 6 May 2014 10:04:55 +0000 (14:04 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 6 May 2014 10:04:55 +0000 (14:04 +0400)
Drag of the line during edit line operation.

20 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/ModuleBase/ModuleBase_OperationDescription.cpp
src/ModuleBase/ModuleBase_OperationDescription.h
src/ModuleBase/ModuleBase_PropPanelOperation.cpp [deleted file]
src/ModuleBase/ModuleBase_PropPanelOperation.h [deleted file]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationEditLine.cpp
src/PartSet/PartSet_OperationEditLine.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/XGUI/XGUI_PropertyPanel.cpp

index 2e706ecb97b695885fb0c0062393195d865eb21c..b154decb009ed0e9e21ba1c885e7f0bfdeb7f47e 100644 (file)
@@ -6,7 +6,6 @@ SET(PROJECT_HEADERS
        ModuleBase_IOperation.h
        ModuleBase_Operation.h
        ModuleBase_OperationDescription.h       
-       ModuleBase_PropPanelOperation.h
        ModuleBase_ModelWidget.h
        ModuleBase_WidgetFactory.h
        ModuleBase_WidgetPoint2D.h
@@ -18,7 +17,6 @@ SET(PROJECT_SOURCES
        ModuleBase_IOperation.cpp
        ModuleBase_Operation.cpp
        ModuleBase_OperationDescription.cpp
-       ModuleBase_PropPanelOperation.cpp
        ModuleBase_WidgetFactory.cpp
        ModuleBase_WidgetPoint2D.cpp
        ModuleBase_WidgetSwitch.cpp
index 2dc4b8f0512af9c1e29e6bfe3bfec59298b533ac..e742c055393a02e4d1d582406fbc71b82bc2d27a 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ModuleBase_Operation.cpp
  *
- *  Created on: May 5, 2014
- *      Author: nds
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
  */
 
 #include "ModuleBase_Operation.h"
index 2f2aca0fa23a1cc3c0e2d15c77428788650ed21d..43c225dd147802f48e5fc3c3bd22209d596f567a 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ModuleBase_Operation.h
  *
- *  Created on: May 5, 2014
- *      Author: nds
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
  */
 
 
index a9bd201ac456ab19094095dd9dd31292f99c18e6..692c5721a924777084540403c7a2eee2be51af45 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ModuleBase_OperationDescription.cpp
  *
- *  Created on: May 5, 2014
- *      Author: nds
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
  */
 
 #include <ModuleBase_OperationDescription.h>
index aedb625b26f8b6d6a757800031e7ca3c71b341d1..56b37c28eec66a01ceae2117a82bcc3e24a44f44 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ModuleBase_OperationDescription.h
  *
- *  Created on: May 5, 2014
- *      Author: nds
+ *  Created on: Apr 2, 2014
+ *      Author: sbh
  */
 
 #ifndef MODULEBASE_OPERATIONDESCRIPTION_H
diff --git a/src/ModuleBase/ModuleBase_PropPanelOperation.cpp b/src/ModuleBase/ModuleBase_PropPanelOperation.cpp
deleted file mode 100644 (file)
index a35aaf7..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ModuleBase_PropPanelOperation.cpp
- *
- *  Created on: Apr 2, 2014
- *      Author: sbh
- */
-
-#include <ModuleBase_PropPanelOperation.h>
-#include <QString>
-
-/*!
- \brief Constructor
- \param XGUI_Workshop - workshop for this operation
-
- Constructs an empty operation. Constructor should work very fast because many
- operators may be created after starting workshop but only several from them
- may be used. As result this constructor stores given workshop in myApp field
- and set Waiting status.
- */
-ModuleBase_PropPanelOperation::ModuleBase_PropPanelOperation(const QString& theId, QObject* parent)
-: ModuleBase_Operation(theId, parent)
-{
-}
-
-/*!
- * \brief Destructor
- */
-ModuleBase_PropPanelOperation::~ModuleBase_PropPanelOperation()
-{
-
-}
-
diff --git a/src/ModuleBase/ModuleBase_PropPanelOperation.h b/src/ModuleBase/ModuleBase_PropPanelOperation.h
deleted file mode 100644 (file)
index c6dc068..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ModuleBase_PropPanelOperation.h
- *
- *  Created on: Apr 2, 2014
- *      Author: sbh
- */
-
-#ifndef MODULEBASE_PROPPANELOPERATION_H
-#define MODULEBASE_PROPPANELOPERATION_H
-
-#include <ModuleBase.h>
-#include <ModuleBase_Operation.h>
-
-#include <QObject>
-#include <QString>
-
-#include <memory>
-
-/*!
- * \class ModuleBase_PropPanelOperation
- *
- */
-class MODULEBASE_EXPORT ModuleBase_PropPanelOperation: public ModuleBase_Operation
-{
-
-  Q_OBJECT
-
-public:
-  ModuleBase_PropPanelOperation(const QString& theId = "", QObject* parent = 0);
-  virtual ~ModuleBase_PropPanelOperation();
-
-  /*!
-   *  \brief Returns XML representation of the operation's widget.
-   *  \return XML QString
-   *
-   *  Returns XML representation of the operation's widget.
-   */
-  const QString& xmlRepresentation() const
-  {
-    return myXmlRepr;
-  }
-
-  /*!
-   *  \brief Sets XML representation of the operation's widget.
-   *  \param xmlRepr - XML QString
-   *
-   *  Sets XML representation of the operation's widget.
-   */
-  void setXmlRepresentation(const QString& xmlRepr)
-  {
-    this->myXmlRepr = xmlRepr;
-  }
-
-
-  /*
-   *  Returns a short description of operation (will be
-   *  inserted in title of property panel)
-   */
-  const QString& description() const
-  {
-    return myDescription;
-  }
-
-  /*
-   *  Sets a short description of operation (will be
-   *  inserted in title of property panel)
-   */
-  void setDescription(const QString& theDescription)
-  {
-    this->myDescription = theDescription;
-  }
-
-private:
-  //!< Next fields could be extracted into a subclass;
-  QString myXmlRepr;
-  QString myDescription;
-};
-
-#endif //MODULEBASE_PROPPANELOPERATION_H
index ab27df2df1fcee51d5f11936f38f6c7c89314bca..e5212c7e85f70d8d4f61cf562f204976ca77dfd3 100644 (file)
@@ -10,7 +10,6 @@
 #include <ModuleBase_MetaWidget.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
-#include <ModuleBase_PropPanelOperation.h>
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetSwitch.h>
 
index 6bfffa8ce5b65010ec692947c9a81be88f880932..36a58e67e9e82b4f4c895c8c902705934bbb2cf8 100644 (file)
@@ -57,6 +57,8 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
 
   connect(myWorkshop->selector(), SIGNAL(selectionChanged()), 
           this, SLOT(onSelectionChanged()));
+  connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)),
+          this, SLOT(onMousePressed(QMouseEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)),
           this, SLOT(onMouseReleased(QMouseEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)),
@@ -110,7 +112,7 @@ void PartSet_Module::onFeatureTriggered()
   
 void PartSet_Module::launchOperation(const QString& theCmdId)
 {
-  ModuleBase_Operation* anOperation = createOperation(theCmdId);
+  ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
   sendOperation(anOperation);
 }
 
@@ -142,34 +144,39 @@ void PartSet_Module::onSelectionChanged()
   }
 }
 
+void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+  {
+    gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(),
+                                                     myWorkshop->viewer()->activeView());
+    aPreviewOp->mousePressed(aPnt, theEvent);
+  }
+}
+
 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
 {
-  QPoint aPoint = theEvent->pos();
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
-    if (aSelector) {
-      Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
-      if ( !aView3d.IsNull() ) {
-        gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
-        aPreviewOp->mouseReleased(aPnt);
-      }
-    }
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+  {
+    gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(),
+                                                     myWorkshop->viewer()->activeView());
+    aPreviewOp->mouseReleased(aPnt, theEvent);
   }
 }
 
 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
 {
-  QPoint aPoint = theEvent->pos();
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
-    if ( !aView3d.IsNull() ) {
-      gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
-      aPreviewOp->mouseMoved(aPnt);
-    }
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+  {
+    gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(),
+                                                     myWorkshop->viewer()->activeView());
+    aPreviewOp->mouseMoved(aPnt, theEvent);
   }
 }
 
@@ -215,37 +222,41 @@ void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> th
   visualizePreview(theFeature, isDisplay);
 }
 
-ModuleBase_Operation* PartSet_Module::createOperation(const QString& theCmdId)
+ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
 {
-  std::string aStdCmdId = theCmdId.toStdString();
-  if (aStdCmdId == "EditLine")
-    aStdCmdId = "SketchLine";
+  // get operation xml description
+  std::string aStdCmdId = theCmdId;
+  if (aStdCmdId == PartSet_OperationEditLine::Type())
+    aStdCmdId = PartSet_OperationSketchLine::Type();
   std::string aPluginFileName = featureFile(aStdCmdId);
   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
   aWdgReader.readAll();
   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
   std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
+
+  // create the operation
   ModuleBase_Operation* anOperation;
-  if (theCmdId == "Sketch" ) {
-    anOperation = new PartSet_OperationSketch(theCmdId, this);
+  if (theCmdId == PartSet_OperationSketch::Type()) {
+    anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
   }
-  else if(theCmdId == "SketchLine" || theCmdId == "EditLine") {
+  else if(theCmdId == PartSet_OperationSketchLine::Type() ||
+          theCmdId == PartSet_OperationEditLine::Type()) {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
     boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
     if (aCurOperation)
       aSketchFeature = aCurOperation->feature();
-    if (theCmdId == "SketchLine")
-      anOperation = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
+    if (theCmdId == PartSet_OperationSketchLine::Type())
+      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature);
     else
-      anOperation = new PartSet_OperationEditLine(theCmdId, this, aSketchFeature);
+      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature);
   }
   else {
-    anOperation = new ModuleBase_Operation(theCmdId, this);
+    anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
   }
   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
 
-  // connect
+  // connect the operation
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
     connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
@@ -259,7 +270,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const QString& theCmdId)
               this, SLOT(onPlaneSelected(double, double, double)));
     }
   }
-
   return anOperation;
 }
 
index 68fe21e6ff22071e2d03136e57feaa5ae5b260cf..03207f25273d751d8110922cf89607d0efe39706 100644 (file)
@@ -53,11 +53,15 @@ public slots:
   /// SLOT, that is called by the selection in the viewer is changed.
   /// The selection is sent to the current operation if it listens selection.
   void onSelectionChanged();
-  /// SLOT, that is called by mouse click in the viewer.
+  /// SLOT, that is called by mouse press in the viewer.
+  /// The mouse released point is sent to the current operation to be processed.
+  /// \param theEvent the mouse event
+  void onMousePressed(QMouseEvent* theEvent);
+  /// SLOT, that is called by mouse release in the viewer.
   /// The mouse released point is sent to the current operation to be processed.
   /// \param theEvent the mouse event
   void onMouseReleased(QMouseEvent* theEvent);
-  /// SLOT, that is called by the selection in the viewer is changed.
+  /// SLOT, that is called by mouse move in the viewer.
   /// The mouse moved point is sent to the current operation to be processed.
   /// \param theEvent the mouse event
   void onMouseMoved(QMouseEvent* theEvent);
@@ -82,7 +86,7 @@ public slots:
 protected:
   /// Creates a new operation
   /// \param theCmdId the operation name
-  ModuleBase_Operation* createOperation(const QString& theCmdId);
+  ModuleBase_Operation* createOperation(const std::string& theCmdId);
 
   /// Sends the operation
   /// \param theOperation the operation
index 72020fb9ac11a479596aa97f8a33e97127f988db..7841945757e335b9f7c0955075537b1bc4ec9925 100644 (file)
@@ -3,21 +3,21 @@
 // Author:      Natalia ERMOLAEVA
 
 #include <PartSet_OperationEditLine.h>
+#include <PartSet_Tools.h>
 
 #include <SketchPlugin_Feature.h>
 #include <GeomDataAPI_Point2D.h>
-#include <GeomDataAPI_Point.h>
-#include <GeomDataAPI_Dir.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 
-#include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Line.h>
 
 #ifdef _DEBUG
 #include <QDebug>
 #endif
 
+#include <QMouseEvent>
+
 using namespace std;
 
 PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId,
@@ -39,8 +39,8 @@ bool PartSet_OperationEditLine::isGranted() const
 std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   std::list<int> aModes;
-  //if (theFeature != feature())
-  //  aModes.push_back(TopAbs_VERTEX);
+  aModes.push_back(TopAbs_VERTEX);
+  aModes.push_back(TopAbs_EDGE);
   return aModes;
 }
 
@@ -49,82 +49,30 @@ void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeat
   setFeature(theFeature);
 }
 
-void PartSet_OperationEditLine::mouseReleased(const gp_Pnt& thePoint)
+void PartSet_OperationEditLine::mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent)
 {
-  /*switch (myPointSelectionMode)
-  {
-    case SM_FirstPoint: {
-      setLinePoint(thePoint, LINE_ATTR_START);
-      myPointSelectionMode = SM_SecondPoint;
-    }
-    break;
-    case SM_SecondPoint: {
-      setLinePoint(thePoint, LINE_ATTR_END);
-      myPointSelectionMode = SM_None;
-    }
-    break;
-    case SM_None: {
-
-    }
-    break;
-    default:
-      break;
-  }
-*/
+  if (!(theEvent->buttons() &  Qt::LeftButton))
+    return;
+  myCurPressed = thePoint;
 }
 
-void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint)
+void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent)
 {
-/*  switch (myPointSelectionMode)
-  {
-    case SM_SecondPoint:
-      setLinePoint(thePoint, LINE_ATTR_END);
-      break;
-    case SM_None: {
-      boost::shared_ptr<ModelAPI_Feature> aPrevFeature = feature();
-      // stop the last operation
-      commitOperation();
-      document()->finishOperation();
-      //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX);
-      // start a new operation
-      document()->startOperation();
-      startOperation();
-      // use the last point of the previous feature as the first of the new one
-      setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START);
-      myPointSelectionMode = SM_SecondPoint;
-
-      emit featureConstructed(aPrevFeature, FM_Deactivation);
-    }
-    break;
-    default:
-      break;
-  }
-*/
-}
+  if (!(theEvent->buttons() &  Qt::LeftButton))
+    return;
 
-void PartSet_OperationEditLine::keyReleased(const int theKey)
-{
-/*  switch (theKey) {
-    case Qt::Key_Escape: {
-      if (myPointSelectionMode != SM_None)
-        emit featureConstructed(feature(), FM_Abort);
-      abort();
-    }
-    break;
-    case Qt::Key_Return: {
-      if (myPointSelectionMode != SM_None) {
-        emit featureConstructed(feature(), FM_Abort);
-        myPointSelectionMode = SM_FirstPoint;
-        document()->abortOperation();
-      }
-      else
-        myPointSelectionMode = SM_FirstPoint;
-    }
-    break;
-    default:
-    break;
-  }
-  */
+  double aCurX, aCurY;
+  PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, aCurX, aCurY);
+
+  double aX, anY;
+  PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY);
+
+  double aDeltaX = aX - aCurX;
+  double aDeltaY = anY - aCurY;
+
+  moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_START);
+  moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_END);
+  myCurPressed = thePoint;
 }
 
 void PartSet_OperationEditLine::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
@@ -136,71 +84,26 @@ void PartSet_OperationEditLine::setSelected(boost::shared_ptr<ModelAPI_Feature>
   commit();
 
   if (theFeature)
-    emit launchOperation("EditLine", theFeature);
+    emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
 }
 
 void PartSet_OperationEditLine::startOperation()
 {
-  //PartSet_OperationSketchBase::startOperation();
-  //myPointSelectionMode = SM_FirstPoint;
-}
-
-void PartSet_OperationEditLine::stopOperation()
-{
-  PartSet_OperationSketchBase::stopOperation();
-  //myPointSelectionMode = SM_None;
+  // do nothing in order to do not create a new feature
 }
 
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
 {
+  // do nothing in order to do not create a new feature
   return boost::shared_ptr<ModelAPI_Feature>();
 }
 
-void PartSet_OperationEditLine::setLinePoint(const gp_Pnt& thePoint,
+void  PartSet_OperationEditLine::moveLinePoint(double theDeltaX, double theDeltaY,
                                                const std::string& theAttribute)
 {
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
 
-  double aX = 0;
-  double anY = 0;
-  convertTo2D(thePoint, aX, anY);
-  aPoint->setValue(aX, anY);
-}
-
-void PartSet_OperationEditLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
-                                               const std::string& theSourceAttribute,
-                                               const std::string& theAttribute)
-{
-  boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theSourceAttribute));
-  double aX = aPoint->x();
-  double anY = aPoint->y();
-
-  aData = feature()->data();
-  aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
-  aPoint->setValue(aX, anY);
-}
-
-void PartSet_OperationEditLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
-{
-  if (!mySketch)
-    return;
-
-  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
-  boost::shared_ptr<ModelAPI_Data> aData = mySketch->data();
-
-  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
-
-  boost::shared_ptr<GeomDataAPI_Dir> aX = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
-  boost::shared_ptr<GeomDataAPI_Dir> anY = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
-
-  gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z());
-  theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
-  theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
+  aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
 }
index 5ce170bbca1e5eaed6b6c52bef9c1ed3860b0aff..28ae00298202162d6157785adea0bb640d7399e8 100644 (file)
@@ -10,6 +10,8 @@
 #include <PartSet_OperationSketchBase.h>
 #include <QObject>
 
+class QMouseEvent;
+
 /*!
  \class PartSet_OperationEditLine
  * \brief The operation for the sketch feature creation
 class PARTSET_EXPORT PartSet_OperationEditLine : public PartSet_OperationSketchBase
 {
   Q_OBJECT
+public:
+  /// Returns the operation type key
+  static std::string Type() { return "EditLine"; }
+
 public:
   /// Constructor
   /// \param theId the feature identifier
@@ -40,15 +46,14 @@ public:
   /// \param theFeature the feature
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
 
-  /// Gives the current selected objects to be processed by the operation
+  /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
-  virtual void mouseReleased(const gp_Pnt& thePoint);
+  /// \param theEvent the mouse event
+  virtual void mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent);
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
-  virtual void mouseMoved(const gp_Pnt& thePoint);
-  /// Processes the key pressed in the view
-  /// \param theKey a key value
-  virtual void keyReleased(const int theKey);
+  /// \param theEvent the mouse event
+  virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent);
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theFeature the selected feature
@@ -56,25 +61,12 @@ public:
   virtual void setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
                            const TopoDS_Shape& theShape);
 
-signals:
-  /// signal about the sketch plane is selected
-  /// \param theX the value in the X direction of the plane
-  /// \param theX the value in the Y direction value of the plane
-  /// \param theX the value in the Z direction of the plane
-  void localContextChanged(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           int theMode);
-
 protected:
   /// \brief Virtual method called when operation is started
   /// Virtual method called when operation started (see start() method for more description)
   /// After the parent operation body perform, set sketch feature to the created line feature
   virtual void startOperation();
 
-  /// \brief Virtual method called when operation is started
-  /// Virtual method called when operation stopped - committed or aborted.
-  /// After the parent operation body perform, reset selection point mode of the operation
-  virtual void stopOperation();
-
   /// Creates an operation new feature
   /// Returns NULL feature. This is an operation of edition, not creation.
   /// \returns the created feature
@@ -82,30 +74,15 @@ protected:
 
 protected:
   /// \brief Save the point to the line.
-  /// \param thePoint the 3D point in the viewer
-  /// \param theAttribute the start or end attribute of the line
-  void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
-
-  /// \brief Set the point to the line by the point of the source line.
-  /// \param theSourceFeature the feature, where the point is obtained
-  /// \param theSourceAttribute the start or end attribute of the source line
+  /// \param theDeltaX the delta for X coordinate is moved
+  /// \param theDeltaY the delta for Y coordinate is moved
   /// \param theAttribute the start or end attribute of the line
-  void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
-                                               const std::string& theSourceAttribute,
-                                               const std::string& theAttribute);
-  /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
-  /// \param thePoint the 3D point in the viewer
-  /// \param theX the X coordinate
-  /// \param theY the Y coordinate
-  void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY);
-
-protected:
-  ///< Structure to lists the possible types of point selection modes
-  enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
+  void  moveLinePoint(double theDeltaX, double theDeltaY,
+                      const std::string& theAttribute);
 
 private:
   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
-  //PointSelectionMode myPointSelectionMode; ///< point selection mode
+  gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
 };
 
 #endif
index 8f2b4ae09109027d212b265411fe02fa049e08f1..0fb1833484e16268f3a6290f424cc6618c6892e7 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <PartSet_OperationSketch.h>
 
+#include <PartSet_OperationEditLine.h>
+
 #include <SketchPlugin_Sketch.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDouble.h>
@@ -49,7 +51,7 @@ void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> th
     myIsEditMode = true;
   }
   else if (theFeature)
-    emit launchOperation("EditLine", theFeature);
+    emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
 }
 
 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
index 47cb5031f01bb3e0478f382438311928f83581f6..b30ce2927526645617d414260eaf1661c247d734 100644 (file)
 class PARTSET_EXPORT PartSet_OperationSketch : public PartSet_OperationSketchBase
 {
   Q_OBJECT
+public:
+  /// Returns the operation type key
+  static std::string Type() { return "Sketch"; }
+
 public:
   /// Constructor
   /// \param theId the feature identifier
index aeeb7c842ddfb21e488aa185d0a5cf048ef8dfda..a7bcf789a42d06dcdd525c8f16fd041c2de870ce 100644 (file)
@@ -15,6 +15,8 @@
 #include <ModuleBase_Operation.h>
 #include <QObject>
 
+class QMouseEvent;
+
 class GeomAPI_Shape;
 
 /*!
@@ -55,13 +57,20 @@ public:
   virtual void setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
                            const TopoDS_Shape& theShape) {};
 
+  /// Processes the mouse pressed in the point
+  /// \param thePoint a point clicked in the viewer
+  /// \param theEvent the mouse event
+  virtual void mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent) {};
+
   /// Processes the mouse release in the point
   /// \param thePoint a point clicked in the viewer
-  virtual void mouseReleased(const gp_Pnt& thePoint) {};
+  /// \param theEvent the mouse event
+  virtual void mouseReleased(const gp_Pnt& thePoint, QMouseEvent* theEvent) {};
 
   /// Processes the mouse move in the point
   /// \param thePoint a 3D point clicked in the viewer
-  virtual void mouseMoved(const gp_Pnt& thePoint) {};
+  /// \param theEvent the mouse event
+  virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent) {};
 
   /// Processes the key pressed in the view
   /// \param theKey a key value
index e3a3c0f532d530cf3084de7e94cc2c161da8e255..25bc7667366bf59dfe07ccc3fb285caee2ac82c3 100644 (file)
@@ -4,14 +4,13 @@
 
 #include <PartSet_OperationSketchLine.h>
 
+#include <PartSet_Tools.h>
+
 #include <SketchPlugin_Feature.h>
 #include <GeomDataAPI_Point2D.h>
-#include <GeomDataAPI_Point.h>
-#include <GeomDataAPI_Dir.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 
-#include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Line.h>
 
 #ifdef _DEBUG
@@ -47,7 +46,7 @@ std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<
   return aModes;
 }
 
-void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
+void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/)
 {
   switch (myPointSelectionMode)
   {
@@ -62,7 +61,6 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
     }
     break;
     case SM_None: {
-
     }
     break;
     default:
@@ -70,7 +68,7 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
   }
 }
 
-void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
+void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/)
 {
   switch (myPointSelectionMode)
   {
@@ -154,9 +152,8 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
 
-  double aX = 0;
-  double anY = 0;
-  convertTo2D(thePoint, aX, anY);
+  double aX, anY;
+  PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY);
   aPoint->setValue(aX, anY);
 }
 
@@ -174,24 +171,3 @@ void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Featur
   aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
   aPoint->setValue(aX, anY);
 }
-
-void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
-{
-  if (!mySketch)
-    return;
-
-  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
-  boost::shared_ptr<ModelAPI_Data> aData = mySketch->data();
-
-  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
-
-  boost::shared_ptr<GeomDataAPI_Dir> aX = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
-  boost::shared_ptr<GeomDataAPI_Dir> anY = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
-
-  gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z());
-  theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
-  theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
-}
index 604baffa3229daa6fa7f43e0bae0563ce90a2e18..cab05194c55cdfd9ae468784929dbf361cd768bf 100644 (file)
@@ -10,6 +10,8 @@
 #include <PartSet_OperationSketchBase.h>
 #include <QObject>
 
+class QMouseEvent;
+
 /*!
  \class PartSet_OperationSketchLine
  * \brief The operation for the sketch feature creation
 class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
 {
   Q_OBJECT
+
+public:
+  /// Returns the operation type key
+  static std::string Type() { return "SketchLine"; }
+
 public:
   /// Constructor
   /// \param theId the feature identifier
@@ -38,22 +45,16 @@ public:
 
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
-  virtual void mouseReleased(const gp_Pnt& thePoint);
+  /// \param theEvent the mouse event
+  virtual void mouseReleased(const gp_Pnt& thePoint, QMouseEvent* theEvent);
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
-  virtual void mouseMoved(const gp_Pnt& thePoint);
+  /// \param theEvent the mouse event
+  virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent);
   /// Processes the key pressed in the view
   /// \param theKey a key value
   virtual void keyReleased(const int theKey);
 
-signals:
-  /// signal about the sketch plane is selected
-  /// \param theX the value in the X direction of the plane
-  /// \param theX the value in the Y direction value of the plane
-  /// \param theX the value in the Z direction of the plane
-  void localContextChanged(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           int theMode);
-
 protected:
   /// \brief Virtual method called when operation is started
   /// Virtual method called when operation started (see start() method for more description)
@@ -84,11 +85,6 @@ protected:
   void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
                                                const std::string& theSourceAttribute,
                                                const std::string& theAttribute);
-  /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
-  /// \param thePoint the 3D point in the viewer
-  /// \param theX the X coordinate
-  /// \param theY the Y coordinate
-  void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY);
 
 protected:
   ///< Structure to lists the possible types of point selection modes
index 8afc9aec8ab12d26dd304d15ddbe0cb3dac6c513..b2d24c3963eb56eb2edb9363b6692dad9c281949 100644 (file)
@@ -9,12 +9,21 @@
 #include <ProjLib.hxx>
 #include <ElSLib.hxx>
 
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
+#include <SketchPlugin_Sketch.h>
+
 #ifdef _DEBUG
 #include <QDebug>
 #endif
 
 gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
 {
+  if (theView.IsNull())
+    return gp_Pnt();
+
   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
   theView->Eye( XEye, YEye, ZEye );
 
@@ -34,3 +43,25 @@ gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theV
   gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
   return ResultPoint;
 }
+
+void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
+                                double& theX, double& theY)
+{
+  if (!theSketch)
+    return;
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+
+  boost::shared_ptr<GeomDataAPI_Dir> aX = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+  boost::shared_ptr<GeomDataAPI_Dir> anY = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+
+  gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z());
+  theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
+  theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
+}
index 4139385d632fcfdb7905f1f8ad4bbb38f52e11c3..759f490d540b0edd87a4aadc0cfec040ae2fe1b8 100644 (file)
 
 #include <QPoint>
 
+#include <boost/shared_ptr.hpp>
+
 class Handle_V3d_View;
+class ModelAPI_Feature;
 
 /*!
  \class PartSet_Tools
@@ -25,6 +28,13 @@ public:
   /// \param theView a 3D view
   static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
 
+  /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
+  /// \param thePoint the 3D point in the viewer
+  /// \param theSketch the sketch feature
+  /// \param theX the X coordinate
+  /// \param theY the Y coordinate
+  static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
+                          double& theX, double& theY);
 };
 
 #endif
index 2f4cca0ed18d5b4f1d9d8b78145fe35addbf3c81..5067484718d39a2fc1d9fbea5983ce0f6ca6da17 100644 (file)
@@ -8,8 +8,6 @@
 #include <XGUI_Constants.h>
 #include <XGUI_PropertyPanel.h>
 
-#include <ModuleBase_PropPanelOperation.h>
-
 #include <QWidget>
 #include <QVBoxLayout>
 #include <QFrame>