From ac4b6a4d91b075f6bc89a7eac244e03070a92dbf Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 31 Dec 2011 17:51:41 +0000 Subject: [PATCH 1/6] + implement alternative zooming for Inventor style + proper handling of space navigator events + fix bug when assigning user-defined shortcuts git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5369 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Gui/Application.cpp | 3 ++- src/Gui/DlgKeyboardImp.cpp | 2 +- src/Gui/InventorNavigationStyle.cpp | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index c8025328bf..f4e108c6c9 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1437,7 +1437,8 @@ public: (int)event->type()); } try { - if (event->type() == Spaceball::ButtonEvent::ButtonEventType || Spaceball::MotionEvent::MotionEventType) + if (event->type() == Spaceball::ButtonEvent::ButtonEventType || + event->type() == Spaceball::MotionEvent::MotionEventType) return processSpaceballEvent(receiver, event); else return QApplication::notify(receiver, event); diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index fe947dbc19..0e0b3af4bb 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -204,7 +204,7 @@ void DlgCustomKeyboardImp::on_buttonAssign_clicked() editShortcut->clear(); ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut"); - hGrp->SetASCII(name.constData(), accelLineEditShortcut->text().toAscii()); + hGrp->SetASCII(name.constData(), accelLineEditShortcut->text().toUtf8()); buttonAssign->setEnabled(false); buttonReset->setEnabled(true); } diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index 65db39aff4..5c9afd6fcc 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -226,6 +226,7 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) } } } + this->button2down = press; break; case SoMouseButtonEvent::BUTTON3: if (press) { @@ -306,10 +307,12 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) BUTTON1DOWN = 1 << 0, BUTTON3DOWN = 1 << 1, CTRLDOWN = 1 << 2, - SHIFTDOWN = 1 << 3 + SHIFTDOWN = 1 << 3, + BUTTON2DOWN = 1 << 4 }; unsigned int combo = (this->button1down ? BUTTON1DOWN : 0) | + (this->button2down ? BUTTON2DOWN : 0) | (this->button3down ? BUTTON3DOWN : 0) | (this->ctrldown ? CTRLDOWN : 0) | (this->shiftdown ? SHIFTDOWN : 0); @@ -339,6 +342,7 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) break; case BUTTON1DOWN|BUTTON3DOWN: case CTRLDOWN|BUTTON3DOWN: + case CTRLDOWN|SHIFTDOWN|BUTTON2DOWN: newmode = NavigationStyle::ZOOMING; break; From f124396c788b9caec7cf0736f1a463e1a73d65c8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 31 Dec 2011 18:06:12 +0000 Subject: [PATCH 2/6] + implement primitive dialog as task panel git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5370 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Part/Gui/DlgPrimitives.ui | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 5423a5de09..8612951db5 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -966,7 +966,7 @@ - + 0 0 @@ -976,7 +976,7 @@ - + 0 0 @@ -996,7 +996,7 @@ - + 0 0 @@ -1006,7 +1006,7 @@ - + 0 0 @@ -1026,7 +1026,7 @@ - + 0 0 @@ -1036,7 +1036,7 @@ - + 0 0 @@ -1056,7 +1056,7 @@ - + 0 0 @@ -1069,7 +1069,7 @@ - + 0 0 @@ -1089,7 +1089,7 @@ - + 0 0 @@ -1102,7 +1102,7 @@ - + 0 0 From 984ce43fb5ab032b51ca9967998c8b66edbf4caf Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 31 Dec 2011 18:54:45 +0000 Subject: [PATCH 3/6] 0000546: Ellipse added to create primitive dialogue git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5371 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Part/App/AppPart.cpp | 1 + src/Mod/Part/App/PrimitiveFeature.cpp | 59 +++++++++++++++ src/Mod/Part/App/PrimitiveFeature.h | 25 +++++++ src/Mod/Part/Gui/DlgPrimitives.cpp | 20 +++++- src/Mod/Part/Gui/DlgPrimitives.ui | 100 ++++++++++++++++++++++++++ 5 files changed, 203 insertions(+), 2 deletions(-) diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 3905c26443..e2fa70b015 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -156,6 +156,7 @@ void PartExport initPart() Part::CurveNet ::init(); Part::Polygon ::init(); Part::Circle ::init(); + Part::Ellipse ::init(); Part::Vertex ::init(); Part::Line ::init(); Part::Ellipsoid ::init(); diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 0041665321..2aef7aa077 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -38,6 +38,7 @@ # include # include # include +# include # include # include # include @@ -725,3 +726,61 @@ void Wedge::onChanged(const App::Property* prop) } Part::Primitive::onChanged(prop); } + +App::PropertyFloatConstraint::Constraints Ellipse::angleRange = {0.0,360.0,1.0}; + +PROPERTY_SOURCE(Part::Ellipse, Part::Primitive) + + +Ellipse::Ellipse() +{ + ADD_PROPERTY(MajorRadius,(4.0f)); + ADD_PROPERTY(MinorRadius,(4.0f)); + ADD_PROPERTY(Angle0,(0.0f)); + Angle0.setConstraints(&angleRange); + ADD_PROPERTY(Angle1,(360.0f)); + Angle1.setConstraints(&angleRange); +} + +Ellipse::~Ellipse() +{ +} + +short Ellipse::mustExecute() const +{ + if (Angle0.isTouched() || + Angle1.isTouched() || + MajorRadius.isTouched() || + MinorRadius.isTouched()) + return 1; + return Part::Feature::mustExecute(); +} + +App::DocumentObjectExecReturn *Ellipse::execute(void) +{ + gp_Elips ellipse; + ellipse.SetMajorRadius(this->MajorRadius.getValue()); + ellipse.SetMinorRadius(this->MinorRadius.getValue()); + + BRepBuilderAPI_MakeEdge clMakeEdge(ellipse, Base::toRadians(this->Angle0.getValue()), + Base::toRadians(this->Angle1.getValue())); + const TopoDS_Edge& edge = clMakeEdge.Edge(); + this->Shape.setValue(edge); + + return App::DocumentObject::StdReturn; +} + +void Ellipse::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + if (prop == &MajorRadius || prop == &MinorRadius || prop == &Angle0 || prop == &Angle1){ + try { + App::DocumentObjectExecReturn *ret = recompute(); + delete ret; + } + catch (...) { + } + } + } + Part::Feature::onChanged(prop); +} diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 250bf1564a..fe1eb06091 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -265,6 +265,31 @@ protected: void onChanged(const App::Property* prop); }; +class Ellipse : public Part::Primitive +{ + PROPERTY_HEADER(Part::Ellipse); + +public: + Ellipse(); + virtual ~Ellipse(); + + App::PropertyFloat MajorRadius; + App::PropertyFloat MinorRadius; + App::PropertyAngle Angle0; + App::PropertyAngle Angle1; + + /** @name methods override feature */ + //@{ + /// recalculate the Feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + void onChanged(const App::Property*); + //@} + +private: + static App::PropertyFloatConstraint::Constraints angleRange; +}; + } //namespace Part diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 30cdb79d13..04b5462f9c 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -312,7 +312,23 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.circleAngle1->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 10) { // vertex + else if (ui.comboBox1->currentIndex() == 10) { // ellipse + name = QString::fromAscii(doc->getUniqueObjectName("Ellipse").c_str()); + cmd = QString::fromAscii( + "App.ActiveDocument.addObject(\"Part::Ellipse\",\"%1\")\n" + "App.ActiveDocument.%1.MajorRadius=%2\n" + "App.ActiveDocument.%1.MinorRadius=%3\n" + "App.ActiveDocument.%1.Angle0=%4\n" + "App.ActiveDocument.%1.Angle1=%5\n" + "App.ActiveDocument.%1.Placement=%6\n") + .arg(name) + .arg(ui.ellipseMajorRadius->value(),0,'f',2) + .arg(ui.ellipseMinorRadius->value(),0,'f',2) + .arg(ui.ellipseAngle0->value(),0,'f',2) + .arg(ui.ellipseAngle1->value(),0,'f',2) + .arg(placement); + } + else if (ui.comboBox1->currentIndex() == 11) { // vertex name = QString::fromAscii(doc->getUniqueObjectName("Vertex").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Vertex\",\"%1\")\n" @@ -326,7 +342,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) .arg(ui.vertexZ->value(),0,'f',2) .arg(placement); } - else if (ui.comboBox1->currentIndex() == 11) { // line + else if (ui.comboBox1->currentIndex() == 12) { // line name = QString::fromAscii(doc->getUniqueObjectName("Line").c_str()); cmd = QString::fromAscii( "App.ActiveDocument.addObject(\"Part::Line\",\"%1\")\n" diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 8612951db5..8f227b6fbd 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -84,6 +84,11 @@ Circle + + + Ellipse + + Point @@ -1320,6 +1325,101 @@ + + + + + + + + Major radius: + + + + + + + 1000000000.000000000000000 + + + 4.000000000000000 + + + + + + + Minor radius: + + + + + + + 1000000000.000000000000000 + + + 2.000000000000000 + + + + + + + Angle 1: + + + + + + + 360.000000000000000 + + + 0.000000000000000 + + + + + + + Angle 2: + + + + + + + 0.000000000000000 + + + 360.000000000000000 + + + 1.000000000000000 + + + 360.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 131 + + + + + + From 20f8a50909301c605334b147ceaa58bf98ca1758 Mon Sep 17 00:00:00 2001 From: mrlukeparry Date: Sat, 31 Dec 2011 20:01:24 +0000 Subject: [PATCH 4/6] Remove un-necessary GL command that seemed to cause rendering artifacts. git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5372 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index ccd27a3f18..2896a54b86 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp @@ -241,9 +241,6 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) state->push(); - glPixelStorei(GL_UNPACK_ROW_LENGTH, srcw); - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); glDisable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); @@ -282,7 +279,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) glEnd(); // Reset the Mode - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPopAttrib(); state->pop(); } From ebd4a35297e5c588119ea62c239882d08586a2f2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 1 Jan 2012 12:44:08 +0000 Subject: [PATCH 5/6] 0000555: 3D navigation using a two-button laptop touchpad git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5373 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Gui/CMakeLists.txt | 1 + src/Gui/Makefile.am | 1 + src/Gui/NavigationStyle.h | 14 ++ src/Gui/SoFCDB.cpp | 1 + src/Gui/TouchpadNavigationStyle.cpp | 346 ++++++++++++++++++++++++++++ 5 files changed, 363 insertions(+) create mode 100644 src/Gui/TouchpadNavigationStyle.cpp diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 96d196a61e..b0e8968b5e 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -558,6 +558,7 @@ SET(View3D_CPP_SRCS InventorNavigationStyle.cpp CADNavigationStyle.cpp BlenderNavigationStyle.cpp + TouchpadNavigationStyle.cpp SplitView3DInventor.cpp View.cpp View3DInventor.cpp diff --git a/src/Gui/Makefile.am b/src/Gui/Makefile.am index 60d706664f..1cf4fcc163 100644 --- a/src/Gui/Makefile.am +++ b/src/Gui/Makefile.am @@ -346,6 +346,7 @@ libFreeCADGui_la_SOURCES=\ ToolBarManager.cpp \ ToolBox.cpp \ ToolBoxManager.cpp \ + TouchpadNavigationStyle.cpp \ Transform.cpp \ Transform.h \ Tree.cpp \ diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 4186d9e2fe..5b7087ef1b 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -279,6 +279,20 @@ private: SbBool lockButton1; }; +class GuiExport TouchpadNavigationStyle : public UserNavigationStyle { + typedef UserNavigationStyle inherited; + + TYPESYSTEM_HEADER(); + +public: + TouchpadNavigationStyle(); + ~TouchpadNavigationStyle(); + const char* mouseButtons(ViewerMode); + +protected: + SbBool processSoEvent(const SoEvent * const ev); +}; + } // namespace Gui #endif // GUI_NAVIGATIONSTYLE_H diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index c2dd99133e..46435be068 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -123,6 +123,7 @@ void Gui::SoFCDB::init() InventorNavigationStyle ::init(); CADNavigationStyle ::init(); BlenderNavigationStyle ::init(); + TouchpadNavigationStyle ::init(); qRegisterMetaType("Base::Vector3f"); qRegisterMetaType("Base::Vector3d"); diff --git a/src/Gui/TouchpadNavigationStyle.cpp b/src/Gui/TouchpadNavigationStyle.cpp new file mode 100644 index 0000000000..e192e11d6b --- /dev/null +++ b/src/Gui/TouchpadNavigationStyle.cpp @@ -0,0 +1,346 @@ +/*************************************************************************** + * Copyright (c) 2012 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include "InventorAll.h" +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include + +#include +#include "NavigationStyle.h" +#include "View3DInventorViewer.h" +#include "Application.h" +#include "MenuManager.h" +#include "MouseSelection.h" + +using namespace Gui; + +// ---------------------------------------------------------------------------------- + +/* TRANSLATOR Gui::TouchpadNavigationStyle */ + +TYPESYSTEM_SOURCE(Gui::TouchpadNavigationStyle, Gui::UserNavigationStyle); + +TouchpadNavigationStyle::TouchpadNavigationStyle() +{ +} + +TouchpadNavigationStyle::~TouchpadNavigationStyle() +{ +} + +const char* TouchpadNavigationStyle::mouseButtons(ViewerMode mode) +{ + switch (mode) { + case NavigationStyle::SELECTION: + return QT_TR_NOOP("Press left mouse button"); + case NavigationStyle::PANNING: + return QT_TR_NOOP("Press SHIFT button"); + case NavigationStyle::DRAGGING: + return QT_TR_NOOP("Press ALT button"); + case NavigationStyle::ZOOMING: + return QT_TR_NOOP("Press PgUp/PgDown button"); + default: + return "No description"; + } +} + +SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) +{ + // Events when in "ready-to-seek" mode are ignored, except those + // which influence the seek mode itself -- these are handled further + // up the inheritance hierarchy. + if (this->isSeekMode()) { return inherited::processSoEvent(ev); } + + const SoType type(ev->getTypeId()); + + const SbViewportRegion & vp = viewer->getViewportRegion(); + const SbVec2s size(vp.getViewportSizePixels()); + const SbVec2f prevnormalized = this->lastmouseposition; + const SbVec2s pos(ev->getPosition()); + const SbVec2f posn((float) pos[0] / (float) SoQtMax((int)(size[0] - 1), 1), + (float) pos[1] / (float) SoQtMax((int)(size[1] - 1), 1)); + + this->lastmouseposition = posn; + + // Set to TRUE if any event processing happened. Note that it is not + // necessary to restrict ourselves to only do one "action" for an + // event, we only need this flag to see if any processing happened + // at all. + SbBool processed = FALSE; + + const ViewerMode curmode = this->currentmode; + ViewerMode newmode = curmode; + + // Mismatches in state of the modifier keys happens if the user + // presses or releases them outside the viewer window. + if (this->ctrldown != ev->wasCtrlDown()) { + this->ctrldown = ev->wasCtrlDown(); + } + if (this->shiftdown != ev->wasShiftDown()) { + this->shiftdown = ev->wasShiftDown(); + } + if (this->altdown != ev->wasAltDown()) { + this->altdown = ev->wasAltDown(); + } + + // give the nodes in the foreground root the chance to handle events (e.g color bar) + if (!processed && !viewer->isEditing()) { + processed = handleEventInForeground(ev); + if (processed) + return TRUE; + } + + // Keyboard handling + if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { + const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev; + const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE; + switch (event->getKey()) { + case SoKeyboardEvent::LEFT_CONTROL: + case SoKeyboardEvent::RIGHT_CONTROL: + this->ctrldown = press; + break; + case SoKeyboardEvent::LEFT_SHIFT: + case SoKeyboardEvent::RIGHT_SHIFT: + this->shiftdown = press; + break; + case SoKeyboardEvent::LEFT_ALT: + case SoKeyboardEvent::RIGHT_ALT: + this->altdown = press; + break; + case SoKeyboardEvent::H: + processed = TRUE; + viewer->saveHomePosition(); + break; + case SoKeyboardEvent::S: + case SoKeyboardEvent::HOME: + case SoKeyboardEvent::LEFT_ARROW: + case SoKeyboardEvent::UP_ARROW: + case SoKeyboardEvent::RIGHT_ARROW: + case SoKeyboardEvent::DOWN_ARROW: + if (!this->isViewing()) + this->setViewing(true); + break; + case SoKeyboardEvent::PAGE_UP: + if (this->invertZoom) + zoom(viewer->getCamera(), 0.05f); + else + zoom(viewer->getCamera(), -0.05f); + processed = TRUE; + break; + case SoKeyboardEvent::PAGE_DOWN: + if (this->invertZoom) + zoom(viewer->getCamera(), -0.05f); + else + zoom(viewer->getCamera(), 0.05f); + processed = TRUE; + break; + default: + break; + } + } + + // Mouse Button / Spaceball Button handling + if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) { + const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev; + const int button = event->getButton(); + const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE; + + // SoDebugError::postInfo("processSoEvent", "button = %d", button); + switch (button) { + case SoMouseButtonEvent::BUTTON1: + this->lockrecenter = TRUE; + this->button1down = press; + if (press && (this->currentmode == NavigationStyle::SEEK_WAIT_MODE)) { + newmode = NavigationStyle::SEEK_MODE; + this->seekToPoint(pos); // implicitly calls interactiveCountInc() + processed = TRUE; + } + else if (press && (this->currentmode == NavigationStyle::PANNING || + this->currentmode == NavigationStyle::ZOOMING)) { + newmode = NavigationStyle::DRAGGING; + this->centerTime = ev->getTime(); + processed = TRUE; + } + else if (!press && (this->currentmode == NavigationStyle::DRAGGING)) { + SbTime tmp = (ev->getTime() - this->centerTime); + float dci = (float)QApplication::doubleClickInterval()/1000.0f; + if (tmp.getValue() < dci) { + newmode = NavigationStyle::ZOOMING; + } + processed = TRUE; + } + else if (!press && (this->currentmode == NavigationStyle::DRAGGING)) { + this->setViewing(false); + processed = TRUE; + } + else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) { + processed = TRUE; + } + break; + case SoMouseButtonEvent::BUTTON2: + // If we are in edit mode then simply ignore the RMB events + // to pass the event to the base class. + this->lockrecenter = TRUE; + if (!viewer->isEditing()) { + // If we are in zoom or pan mode ignore RMB events otherwise + // the canvas doesn't get any release events + if (this->currentmode != NavigationStyle::ZOOMING && + this->currentmode != NavigationStyle::PANNING && + this->currentmode != NavigationStyle::DRAGGING) { + if (this->isPopupMenuEnabled()) { + if (!press) { // release right mouse button + this->openPopupMenu(event->getPosition()); + } + } + } + } + // Alternative way of rotating & zooming + if (press && (this->currentmode == NavigationStyle::PANNING || + this->currentmode == NavigationStyle::ZOOMING)) { + newmode = NavigationStyle::DRAGGING; + this->centerTime = ev->getTime(); + processed = TRUE; + } + else if (!press && (this->currentmode == NavigationStyle::DRAGGING)) { + SbTime tmp = (ev->getTime() - this->centerTime); + float dci = (float)QApplication::doubleClickInterval()/1000.0f; + if (tmp.getValue() < dci) { + newmode = NavigationStyle::ZOOMING; + } + processed = TRUE; + } + this->button2down = press; + break; + default: + break; + } + } + + // Mouse Movement handling + if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) { + this->lockrecenter = TRUE; + const SoLocation2Event * const event = (const SoLocation2Event *) ev; + if (this->currentmode == NavigationStyle::ZOOMING) { + this->zoomByCursor(posn, prevnormalized); + processed = TRUE; + } + else if (this->currentmode == NavigationStyle::PANNING) { + float ratio = vp.getViewportAspectRatio(); + panCamera(viewer->getCamera(), ratio, this->panningplane, posn, prevnormalized); + processed = TRUE; + } + else if (this->currentmode == NavigationStyle::DRAGGING) { + this->addToLog(event->getPosition(), event->getTime()); + this->spin(posn); + processed = TRUE; + } + } + + // Spaceball & Joystick handling + if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) { + SoMotion3Event * const event = (SoMotion3Event *) ev; + SoCamera * const camera = viewer->getCamera(); + + SbVec3f dir = event->getTranslation(); + if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){ + static float zoomConstant(-.03f); + dir[2] = 0.0;//don't move the cam for z translation. + + SoOrthographicCamera *oCam = static_cast(camera); + oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant); + } + camera->orientation.getValue().multVec(dir,dir); + camera->position = camera->position.getValue() + dir; + camera->orientation = event->getRotation() * camera->orientation.getValue(); + processed = TRUE; + } + + enum { + BUTTON1DOWN = 1 << 0, + BUTTON2DOWN = 1 << 1, + CTRLDOWN = 1 << 2, + SHIFTDOWN = 1 << 3, + ALTDOWN = 1 << 4 + }; + unsigned int combo = + (this->button1down ? BUTTON1DOWN : 0) | + (this->button2down ? BUTTON2DOWN : 0) | + (this->ctrldown ? CTRLDOWN : 0) | + (this->shiftdown ? SHIFTDOWN : 0) | + (this->altdown ? ALTDOWN : 0); + + switch (combo) { + case 0: + if (curmode == NavigationStyle::SPINNING) { break; } + newmode = NavigationStyle::IDLE; + break; + case BUTTON1DOWN: + // make sure not to change the selection when stopping spinning + if (curmode == NavigationStyle::SPINNING) + newmode = NavigationStyle::IDLE; + else + newmode = NavigationStyle::SELECTION; + break; + case CTRLDOWN: + newmode = NavigationStyle::IDLE; + break; + case SHIFTDOWN: + newmode = NavigationStyle::PANNING; + break; + case ALTDOWN: + case CTRLDOWN|SHIFTDOWN: + newmode = NavigationStyle::DRAGGING; + break; + case CTRLDOWN|SHIFTDOWN|BUTTON1DOWN: + newmode = NavigationStyle::ZOOMING; + break; + default: + break; + } + + if (newmode != curmode) { + this->setViewingMode(newmode); + } + + // If not handled in this class, pass on upwards in the inheritance + // hierarchy. + if (!processed) + processed = inherited::processSoEvent(ev); + else + return TRUE; + + return processed; +} From b99155c653dc5249ab0f20a2fe6cdb86da028ef8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 1 Jan 2012 13:40:53 +0000 Subject: [PATCH 6/6] + implement multi-selection for Inventor style git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5374 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Gui/InventorNavigationStyle.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index 5c9afd6fcc..42993e7559 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -331,13 +331,14 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) newmode = NavigationStyle::DRAGGING; break; case BUTTON3DOWN: - case SHIFTDOWN|BUTTON1DOWN: + case CTRLDOWN|SHIFTDOWN: + case CTRLDOWN|SHIFTDOWN|BUTTON1DOWN: newmode = NavigationStyle::PANNING; break; case CTRLDOWN: case CTRLDOWN|BUTTON1DOWN: - case CTRLDOWN|SHIFTDOWN: - case CTRLDOWN|SHIFTDOWN|BUTTON1DOWN: + case SHIFTDOWN: + case SHIFTDOWN|BUTTON1DOWN: newmode = NavigationStyle::SELECTION; break; case BUTTON1DOWN|BUTTON3DOWN: @@ -369,7 +370,9 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) // If not handled in this class, pass on upwards in the inheritance // hierarchy. - if ((curmode == NavigationStyle::SELECTION || viewer->isEditing()) && !processed) + if ((curmode == NavigationStyle::SELECTION || + newmode == NavigationStyle::SELECTION || + viewer->isEditing()) && !processed) processed = inherited::processSoEvent(ev); else return TRUE;