#include <XGUI_Workshop.h>
#include <XGUI_Selection.h>
#include <XGUI_SelectionMgr.h>
+#include <ModuleBase_ModelWidget.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_PropertyPanel.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_IWorkshop.h>
PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
: QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false)
{
- ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
- ModuleBase_IViewer* aViewer = aWorkshop->viewer();
+ ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
+ ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
+
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
}
PartSet_SketcherMgr::~PartSet_SketcherMgr()
void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ get2dPoint(theWnd, theEvent, myClickedPoint);
+
//
if (!(theEvent->buttons() & Qt::LeftButton))
return;
if (isSketcher) {
myIsDragging = true;
- get2dPoint(theWnd, theEvent, myCurX, myCurY);
+ get2dPoint(theWnd, theEvent, myCurrentPoint);
myDragDone = false;
launchEditing();
aOperation->commit();
myIsDragging = true;
- get2dPoint(theWnd, theEvent, myCurX, myCurY);
+ get2dPoint(theWnd, theEvent, myCurrentPoint);
myDragDone = false;
// This is necessary in order to finalize previous operation
if (!sketchOperationIdList().contains(aOp->id()))
return;
+ get2dPoint(theWnd, theEvent, myClickedPoint);
+
// Only for sketcher operations
ModuleBase_IViewer* aViewer = aWorkshop->viewer();
if (myIsDragging) {
void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ myClickedPoint.clear();
+
if (myIsDragging) {
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
// 1. it is necessary to save current selection in order to restore it after the features moving
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
double aX, aY;
PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
- double dX = aX - myCurX;
- double dY = aY - myCurY;
+ double dX = aX - myCurrentPoint.myCurX;
+ double dY = aY - myCurrentPoint.myCurY;
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
aDisplayer->updateViewer();
myDragDone = true;
- myCurX = aX;
- myCurY = aY;
+ myCurrentPoint.setValue(aX, aY);
}
}
ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
if (aOperation && aOperation->isEditOperation()) {
std::string aId = aOperation->id().toStdString();
- if ((aId == SketchPlugin_ConstraintLength::ID()) ||
- (aId == SketchPlugin_ConstraintDistance::ID()) ||
- (aId == SketchPlugin_ConstraintRadius::ID()))
+ if (isDistanceOperation(aOperation))
{
// Activate dimension value editing on double click
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
}
}
+void PartSet_SketcherMgr::onApplicationStarted()
+{
+ ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
+ if (aPropertyPanel) {
+ connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
+ this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
+ }
+}
+
+void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
+{
+ if (!myClickedPoint.myIsInitialized)
+ return;
+
+ ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
+ // the distance constraint feature should not use the clickedd point
+ // this is workaround in order to don't throw down the flyout point value,
+ // set by execute() method of these type of features
+ if (isDistanceOperation(aOperation))
+ return;
+
+ PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
+ if (aPnt2dWgt) {
+ aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
+ }
+}
+
+bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) const
+{
+ std::string aId = theOperation ? theOperation->id().toStdString() : "";
+
+ return (aId == SketchPlugin_ConstraintLength::ID()) ||
+ (aId == SketchPlugin_ConstraintDistance::ID()) ||
+ (aId == SketchPlugin_ConstraintRadius::ID());
+}
+
void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
- double& theX, double& theY)
+ Point& thePoint)
{
Handle(V3d_View) aView = theWnd->v3dView();
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
- PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
+ double aX, anY;
+ PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
+ thePoint.setValue(aX, anY);
}
void PartSet_SketcherMgr::launchEditing()
class PartSet_Module;
class ModuleBase_IViewWindow;
+class ModuleBase_ModelWidget;
class ModuleBase_Operation;
class QMouseEvent;
class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
{
Q_OBJECT
+ /// Struct to define gp point, with the state is the point is initialized
+ struct Point
+ {
+ /// Constructor
+ Point()
+ {
+ myIsInitialized = false;
+ }
+ /// Destructor
+ ~Point()
+ {
+ }
+
+ /// clear the initialized flag.
+ void clear()
+ {
+ myIsInitialized = false;
+ }
+ /// set the point and switch on the initialized flag
+ /// \param thePoint the point
+ void setValue(const double theX, const double theY)
+ {
+ myIsInitialized = true;
+ myCurX = theX;
+ myCurY = theY;
+ }
+
+ bool myIsInitialized; /// the state whether the point is set
+ double myCurX, myCurY; /// the point coordinates
+ };
public:
PartSet_SketcherMgr(PartSet_Module* theModule);
void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
+ void onApplicationStarted();
+ void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
private:
+ /// Returns whethe the current operation is a sketch distance - lenght, distance or radius
+ /// \param the operation
+ /// \return a boolean value
+ bool isDistanceOperation(ModuleBase_Operation* theOperation) const;
+
/// Converts mouse position to 2d coordinates.
/// Member myCurrentSketch has to be correctly defined
void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
- double& theX, double& theY);
-
+ Point& thePoint);
typedef QList<AttributePtr> AttributeList;
typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
bool myIsDragging;
bool myDragDone;
- double myCurX, myCurY;
+ Point myCurrentPoint;
+ Point myClickedPoint;
CompositeFeaturePtr myCurrentSketch;