Skip to content

Commit

Permalink
Reuse projection settings from an existing view when creating new par…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
mghansen256 authored and wwmayer committed Dec 20, 2014
1 parent 6af1186 commit ef24aaa
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/Mod/Drawing/Gui/Command.cpp
Expand Up @@ -22,6 +22,8 @@

#include <vector>

#include <App/PropertyGeo.h>

#include <Gui/Action.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
Expand Down Expand Up @@ -282,17 +284,49 @@ void CmdDrawingNewView::activated(int iMsg)
}
}

const std::vector<App::DocumentObject*> 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<Drawing::FeatureView*>(selectedProjections.front());

const App::PropertyFloat* const propX = dynamic_cast<App::PropertyFloat*>(myView->getPropertyByName("X"));
if (propX) {
newX = propX->getValue();
}
const App::PropertyFloat* const propY = dynamic_cast<App::PropertyFloat*>(myView->getPropertyByName("Y"));
if (propY) {
newY = propY->getValue();
}
const App::PropertyFloat* const propScale = dynamic_cast<App::PropertyFloat*>(myView->getPropertyByName("Scale"));
if (propScale) {
newScale = propScale->getValue();
}
const App::PropertyFloat* const propRotation = dynamic_cast<App::PropertyFloat*>(myView->getPropertyByName("Rotation"));
if (propRotation) {
newRotation = propRotation->getValue();
}
const App::PropertyVector* const propDirection = dynamic_cast<App::PropertyVector*>(myView->getPropertyByName("Direction"));
if (propDirection) {
newDirection = propDirection->getValue();
}
}

std::string PageName = pages.front()->getNameInDocument();

openCommand("Create view");
for (std::vector<App::DocumentObject*>::iterator it = shapes.begin(); it != shapes.end(); ++it) {
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();
Expand Down

0 comments on commit ef24aaa

Please sign in to comment.