}
}
-void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
-{
- if (!(theEvent->buttons() & Qt::LeftButton))
- return;
-
- ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- // Use only for sketch operations
- if (aOperation && myCurrentSketch) {
- if (!PartSet_Tools::sketchPlane(myCurrentSketch))
- return;
-
- bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
- bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
-
- // Avoid non-sketch operations
- if ((!isSketchOpe) && (!isSketcher))
- return;
-
- bool isEditing = aOperation->isEditOperation();
-
- // Ignore creation sketch operation
- if ((!isSketcher) && (!isEditing))
- return;
-
- if (theEvent->modifiers()) {
- // If user performs multiselection
- if (isSketchOpe && (!isSketcher))
- if (!aOperation->commit())
- aOperation->abort();
- return;
- }
- // Remember highlighted objects for editing
- ModuleBase_ISelection* aSelect = myWorkshop->selection();
- QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
- QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
- myEditingFeatures.clear();
- myEditingAttr.clear();
- if ((aHighlighted.size() == 0) && (aSelected.size() == 0)) {
- if (isSketchOpe && (!isSketcher))
- // commit previous operation
- if (!aOperation->commit())
- aOperation->abort();
- return;
- }
-
- QObjectPtrList aSelObjects = getSumList(aHighlighted, aSelected);
- if ((aHighlighted.size() == 1) && (aSelected.size() == 0)) {
- // Move by selected shape (vertex). Can be used only for single selection
- foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object());
- if (aFeature) {
- myEditingFeatures.append(aFeature);
- TopoDS_Shape aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- if (aShape.ShapeType() == TopAbs_VERTEX) {
- AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(),
- aShape, myCurrentSketch);
- if (aAttr)
- myEditingAttr.append(aAttr);
- }
- }
- }
- }
- } else {
- // Provide multi-selection. Can be used only for features
- foreach (ObjectPtr aObj, aSelObjects) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
- if (aFeature && (!myEditingFeatures.contains(aFeature)))
- myEditingFeatures.append(aFeature);
- }
-
- }
- // If nothing highlighted - return
- if (myEditingFeatures.size() == 0)
- return;
-
- if (isSketcher) {
- myIsDragging = true;
- get2dPoint(theWnd, theEvent, myCurX, myCurY);
- myDragDone = false;
- myWorkshop->viewer()->enableSelection(false);
- launchEditing();
-
- } else if (isSketchOpe && isEditing) {
- // If selected another object
- aOperation->abort();
-
- myIsDragging = true;
- get2dPoint(theWnd, theEvent, myCurX, myCurY);
- myDragDone = false;
- myWorkshop->viewer()->enableSelection(false);
-
- // This is necessary in order to finalize previous operation
- QApplication::processEvents();
- launchEditing();
- }
- }
-}
-
-
-void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
- double& theX, double& theY)
-{
- Handle(V3d_View) aView = theWnd->v3dView();
- gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
- PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
-}
-
-
-void PartSet_Module::launchEditing()
-{
- if (myEditingFeatures.size() > 0) {
- FeaturePtr aFeature = myEditingFeatures.first();
- std::shared_ptr<SketchPlugin_Feature> aSPFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if (aSPFeature) {
- editFeature(aSPFeature);
- }
- }
-}
-
-void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
-{
- myWorkshop->viewer()->enableSelection(true);
- if (myIsDragging) {
- myIsDragging = false;
- if (myDragDone) {
- myWorkshop->currentOperation()->commit();
- myEditingFeatures.clear();
- myEditingAttr.clear();
- }
- }
-}
-
-
-void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
-{
- if (myIsDragging) {
- ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
- return; // No edit operation activated
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
- Handle(V3d_View) aView = theWnd->v3dView();
- 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;
-
- if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
- (myEditingAttr.size() == 1) &&
- myEditingAttr.first()) {
- // probably we have prehighlighted point
- AttributePtr aAttr = myEditingAttr.first();
- std::string aAttrId = aAttr->id();
- ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
- QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
- // Find corresponded widget to provide dragging
- foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
- if (aWgt->attributeID() == aAttrId) {
- PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
- if (aWgt2d) {
- aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
- break;
- }
- }
- }
- } else {
- foreach(FeaturePtr aFeature, myEditingFeatures) {
- std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if (aSketchFeature) {
- aSketchFeature->move(dX, dY);
- ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
- }
- }
+ // after movement the solver will call the update event: optimization
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
- }
- myDragDone = true;
- myCurX = aX;
- myCurY = aY;
- }
-}
-
-void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
-{
- ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- if (aOperation && aOperation->isEditOperation()) {
- std::string aId = aOperation->id().toStdString();
- if ((aId == SketchPlugin_ConstraintLength::ID()) ||
- (aId == SketchPlugin_ConstraintDistance::ID()) ||
- (aId == SketchPlugin_ConstraintRadius::ID()))
- {
- // Activate dimension value editing on double click
- ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
- QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
- // Find corresponded widget to activate value editing
- foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
- if (aWgt->attributeID() == "ConstraintValue") {
- aWgt->focusTo();
- return;
- }
- }
- }
- }
-}
void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
{