Skip to content

Commit

Permalink
Center new view on Page/ClipGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Jul 23, 2016
1 parent f2bad45 commit 131c34c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
8 changes: 8 additions & 0 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -237,11 +237,19 @@ int DrawPage::addView(App::DocumentObject *docObj)
if(!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()))
return -1;

//position all new views in center of Page (exceptDVDimension)
DrawView* view = dynamic_cast<DrawView*>(docObj);
if (!docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
view->X.setValue(getPageWidth()/2.0);
view->Y.setValue(getPageHeight()/2.0);
}

const std::vector<App::DocumentObject *> currViews = Views.getValues();
std::vector<App::DocumentObject *> newViews(currViews);
newViews.push_back(docObj);
Views.setValues(newViews);
Views.touch();

return Views.getSize();
}

Expand Down
5 changes: 1 addition & 4 deletions src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -58,9 +58,8 @@ const char* DrawView::ScaleTypeEnums[]= {"Document",

PROPERTY_SOURCE(TechDraw::DrawView, App::DocumentObject)



DrawView::DrawView(void)
: autoPos(true)
{
static const char *group = "Drawing view";
ADD_PROPERTY_TYPE(X ,(0),group,App::Prop_None,"X position of the view on the page in modelling units (mm)");
Expand All @@ -73,8 +72,6 @@ DrawView::DrawView(void)

if (isRestoring()) {
autoPos = false;
} else {
autoPos = true;
}
}

Expand Down
20 changes: 0 additions & 20 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -164,11 +164,8 @@ void CmdTechDrawNewPageDef::activated(int iMsg)
Gui::WaitCursor wc;
openCommand("Drawing create page");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str());

// Create the Template Object to attach to the page
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str());

//TODO: why is "Template" property set twice?
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str());
doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str());

Expand Down Expand Up @@ -307,16 +304,12 @@ void CmdTechDrawNewView::activated(int iMsg)
Gui::WaitCursor wc;
const std::vector<App::DocumentObject*> selectedProjections = getSelection().getObjectsOfType(TechDraw::DrawView::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 TechDraw::DrawView* const myView = dynamic_cast<TechDraw::DrawView*>(selectedProjections.front());

newX = myView->X.getValue();
newY = myView->Y.getValue();
newScale = myView->Scale.getValue();
newRotation = myView->Rotation.getValue();

Expand All @@ -335,8 +328,6 @@ void CmdTechDrawNewView::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument());
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.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
Expand Down Expand Up @@ -390,10 +381,6 @@ void CmdTechDrawNewViewSection::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Section");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSection','%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.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
}
updateActive();
Expand Down Expand Up @@ -446,9 +433,6 @@ void CmdTechDrawProjGroup::activated(int iMsg)
std::string SourceName = (*shapes.begin())->getNameInDocument();
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')",multiViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",multiViewName.c_str(),SourceName.c_str());
doCommand(Doc,"App.activeDocument().%s.X = %f", multiViewName.c_str(), page->getPageWidth() / 2);
doCommand(Doc,"App.activeDocument().%s.Y = %f", multiViewName.c_str(), page->getPageHeight() / 2);
doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",multiViewName.c_str());

App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str());
TechDraw::DrawProjGroup *multiView = dynamic_cast<TechDraw::DrawProjGroup *>(docObj);
Expand Down Expand Up @@ -506,8 +490,6 @@ void CmdTechDrawAnnotation::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Annotation");
openCommand("Create Annotation");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewAnnotation','%s')",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.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
updateActive();
commitCommand();
Expand Down Expand Up @@ -748,8 +730,6 @@ void CmdTechDrawSymbol::activated(int iMsg)
doCommand(Doc,"svg = f.read()");
doCommand(Doc,"f.close()");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')",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.Symbol = svg",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
updateActive();
Expand Down

0 comments on commit 131c34c

Please sign in to comment.