From ef24aaa3ce32e0d90a0ccd18274234776e5516b0 Mon Sep 17 00:00:00 2001 From: Michael Georg Hansen Date: Wed, 17 Dec 2014 21:53:57 +0100 Subject: [PATCH] Reuse projection settings from an existing view when creating new part views. Select a part and a view on a drawing page, then the view created for the part will have the same projection settings as the selected view. --- src/Mod/Drawing/Gui/Command.cpp | 42 +++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index 4f317137d..d22550759 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -22,6 +22,8 @@ #include +#include + #include #include #include @@ -282,6 +284,37 @@ void CmdDrawingNewView::activated(int iMsg) } } + const std::vector selectedProjections = getSelection().getObjectsOfType(Drawing::FeatureView::getClassTypeId()); + float newX = 10.0; + float newY = 10.0; + float newScale = 1.0; + float newRotation = 0.0; + Base::Vector3d newDirection(0.0, 0.0, 1.0); + if (!selectedProjections.empty()) { + const Drawing::FeatureView* const myView = dynamic_cast(selectedProjections.front()); + + const App::PropertyFloat* const propX = dynamic_cast(myView->getPropertyByName("X")); + if (propX) { + newX = propX->getValue(); + } + const App::PropertyFloat* const propY = dynamic_cast(myView->getPropertyByName("Y")); + if (propY) { + newY = propY->getValue(); + } + const App::PropertyFloat* const propScale = dynamic_cast(myView->getPropertyByName("Scale")); + if (propScale) { + newScale = propScale->getValue(); + } + const App::PropertyFloat* const propRotation = dynamic_cast(myView->getPropertyByName("Rotation")); + if (propRotation) { + newRotation = propRotation->getValue(); + } + const App::PropertyVector* const propDirection = dynamic_cast(myView->getPropertyByName("Direction")); + if (propDirection) { + newDirection = propDirection->getValue(); + } + } + std::string PageName = pages.front()->getNameInDocument(); openCommand("Create view"); @@ -289,10 +322,11 @@ void CmdDrawingNewView::activated(int iMsg) std::string FeatName = getUniqueObjectName("View"); doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewPart','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Direction = (0.0,0.0,1.0)",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Direction = (%e,%e,%e)",FeatName.c_str(), newDirection.x, newDirection.y, newDirection.z); + doCommand(Doc,"App.activeDocument().%s.X = %e",FeatName.c_str(), newX); + doCommand(Doc,"App.activeDocument().%s.Y = %e",FeatName.c_str(), newY); + doCommand(Doc,"App.activeDocument().%s.Scale = %e",FeatName.c_str(), newScale); + doCommand(Doc,"App.activeDocument().%s.Rotation = %e",FeatName.c_str(), newRotation); doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); } updateActive();