Skip to content

Commit

Permalink
Fix ProjectionGroupItem spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Sep 1, 2016
1 parent 3901d2f commit 27ff991
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 625 deletions.
55 changes: 41 additions & 14 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -207,7 +207,11 @@ void DrawProjGroup::onChanged(const App::Property* prop)
execute();
} else if (prop == &ScaleType ||
prop == &viewOrientationMatrix ||
prop == &Scale ) {
prop == &Scale ||
prop == &Views) {
execute();
} else if (prop == &spacingX ||
prop == &spacingY) {
execute();
}
}
Expand All @@ -229,7 +233,7 @@ App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const
{
for( auto it : Views.getValues() ) {
auto projPtr( dynamic_cast<DrawProjGroupItem *>(it) );
if( projPtr &&
if( projPtr &&
strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
return it;
}
Expand Down Expand Up @@ -473,16 +477,21 @@ bool DrawProjGroup::distributeProjections()
makeViewBbs(viewPtrs, bboxes);

// Now that things are setup, do the spacing
double xSpacing = spacingX.getValue(); //in mm
double ySpacing = spacingY.getValue(); //in mm
double scale = Scale.getValue();
double xSpacing = scale * spacingX.getValue(); //in mm
double ySpacing = scale * spacingY.getValue(); //in mm

if (viewPtrs[0] && viewPtrs[0]->allowAutoPos()) {
if (viewPtrs[0] &&
viewPtrs[0]->allowAutoPos() &&
bboxes[0].IsValid()) {
double displace = std::max(bboxes[0].LengthX() + bboxes[4].LengthX(),
bboxes[0].LengthY() + bboxes[4].LengthY());
viewPtrs[0]->X.setValue(displace / -2.0 - xSpacing);
viewPtrs[0]->Y.setValue(displace / 2.0 + ySpacing);
}
if (viewPtrs[1] && viewPtrs[1]->allowAutoPos()) {
if (viewPtrs[1] &&
viewPtrs[1]->allowAutoPos() &&
bboxes[1].IsValid()) {
viewPtrs[1]->Y.setValue((bboxes[1].LengthY() + bboxes[4].LengthY()) / 2.0 + ySpacing);
}
if (viewPtrs[2] && viewPtrs[2]->allowAutoPos()) {
Expand All @@ -491,30 +500,48 @@ bool DrawProjGroup::distributeProjections()
viewPtrs[2]->X.setValue(displace / 2.0 + xSpacing);
viewPtrs[2]->Y.setValue(displace / 2.0 + ySpacing);
}
if (viewPtrs[3] && viewPtrs[3]->allowAutoPos()) {
if (viewPtrs[3] &&
viewPtrs[3]->allowAutoPos() &&
bboxes[3].IsValid() &&
bboxes[4].IsValid()) {
viewPtrs[3]->X.setValue((bboxes[3].LengthX() + bboxes[4].LengthX()) / -2.0 - xSpacing);
}
if (viewPtrs[4]) { // TODO: Move this check above, and figure out a sane bounding box based on other existing views
}
if (viewPtrs[5] && viewPtrs[5]->allowAutoPos()) {
if (viewPtrs[5] &&
viewPtrs[5]->allowAutoPos() &&
bboxes[5].IsValid() &&
bboxes[4].IsValid()) {
viewPtrs[5]->X.setValue((bboxes[5].LengthX() + bboxes[4].LengthX()) / 2.0 + xSpacing);
}
if (viewPtrs[6] && viewPtrs[6]->allowAutoPos()) { //"Rear"
if (viewPtrs[5])
if (viewPtrs[6] &&
viewPtrs[6]->allowAutoPos() &&
bboxes[6].IsValid()) { //"Rear"
if (viewPtrs[5] &&
bboxes[5].IsValid()) {
viewPtrs[6]->X.setValue(viewPtrs[5]->X.getValue() + bboxes[5].LengthX()/2.0 + xSpacing + bboxes[6].LengthX() / 2.0 );
else
}else if (viewPtrs[4] &&
bboxes[4].IsValid()) {
viewPtrs[6]->X.setValue((bboxes[6].LengthX() + bboxes[4].LengthX()) / 2.0 + xSpacing);
}
}
if (viewPtrs[7] && viewPtrs[7]->allowAutoPos()) {
if (viewPtrs[7] &&
viewPtrs[7]->allowAutoPos() &&
bboxes[7].IsValid()) {
double displace = std::max(bboxes[7].LengthX() + bboxes[4].LengthX(),
bboxes[7].LengthY() + bboxes[4].LengthY());
viewPtrs[7]->X.setValue(displace / -2.0 - xSpacing);
viewPtrs[7]->Y.setValue(displace / -2.0 - ySpacing);
}
if (viewPtrs[8] && viewPtrs[8]->allowAutoPos()) {
if (viewPtrs[8] &&
viewPtrs[8]->allowAutoPos() &&
bboxes[8].IsValid() &&
bboxes[4].IsValid()) {
viewPtrs[8]->Y.setValue((bboxes[8].LengthY() + bboxes[4].LengthY()) / -2.0 - ySpacing);
}
if (viewPtrs[9] && viewPtrs[9]->allowAutoPos()) {
if (viewPtrs[9] &&
viewPtrs[9]->allowAutoPos() &&
bboxes[9].IsValid()) {
double displace = std::max(bboxes[9].LengthX() + bboxes[4].LengthX(),
bboxes[9].LengthY() + bboxes[4].LengthY());
viewPtrs[9]->X.setValue(displace / 2.0 + xSpacing);
Expand Down
208 changes: 104 additions & 104 deletions src/Mod/TechDraw/App/DrawProjGroupItem.cpp
@@ -1,104 +1,104 @@
/***************************************************************************
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
* *
* 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 <sstream>
#endif

#include <strstream>
#include <Base/Console.h>
#include <Base/Writer.h>

#include "DrawProjGroupItem.h"

#include <Mod/TechDraw/App/DrawProjGroupItemPy.h> // generated from DrawProjGroupItemPy.xml

using namespace TechDraw;

const char* DrawProjGroupItem::TypeEnums[] = {"Front",
"Left",
"Right",
"Rear",
"Top",
"Bottom",
"FrontTopLeft",
"FrontTopRight",
"FrontBottomLeft",
"FrontBottomRight",
NULL};


PROPERTY_SOURCE(TechDraw::DrawProjGroupItem, TechDraw::DrawViewPart)

DrawProjGroupItem::DrawProjGroupItem(void)
{
Type.setEnums(TypeEnums);
ADD_PROPERTY(Type, ((long)0));

//projection group controls these
Direction.setStatus(App::Property::Hidden,true);
XAxisDirection.setStatus(App::Property::Hidden,true);
Scale.setStatus(App::Property::ReadOnly,true);
ScaleType.setStatus(App::Property::ReadOnly,true);
}

short DrawProjGroupItem::mustExecute() const
{
if (Type.isTouched())
return 1;
return TechDraw::DrawViewPart::mustExecute();
}

void DrawProjGroupItem::onChanged(const App::Property *prop)
{
TechDraw::DrawViewPart::onChanged(prop);

//TODO: Should we allow changes to the Type here? Seems that should be handled through DrawProjGroup
if (prop == &Type && Type.isTouched()) {
if (!isRestoring()) {
execute();
}
}

}

DrawProjGroupItem::~DrawProjGroupItem()
{
}

void DrawProjGroupItem::onDocumentRestored()
{
// Rebuild the view
execute();
}


PyObject *DrawProjGroupItem::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawProjGroupItemPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
/***************************************************************************
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
* *
* 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 <sstream>
#endif

#include <strstream>
#include <Base/Console.h>
#include <Base/Writer.h>

#include "DrawProjGroupItem.h"

#include <Mod/TechDraw/App/DrawProjGroupItemPy.h> // generated from DrawProjGroupItemPy.xml

using namespace TechDraw;

const char* DrawProjGroupItem::TypeEnums[] = {"Front",
"Left",
"Right",
"Rear",
"Top",
"Bottom",
"FrontTopLeft",
"FrontTopRight",
"FrontBottomLeft",
"FrontBottomRight",
NULL};


PROPERTY_SOURCE(TechDraw::DrawProjGroupItem, TechDraw::DrawViewPart)

DrawProjGroupItem::DrawProjGroupItem(void)
{
Type.setEnums(TypeEnums);
ADD_PROPERTY(Type, ((long)0));

//projection group controls these
Direction.setStatus(App::Property::Hidden,true);
XAxisDirection.setStatus(App::Property::Hidden,true);
Scale.setStatus(App::Property::ReadOnly,true);
ScaleType.setStatus(App::Property::ReadOnly,true);
}

short DrawProjGroupItem::mustExecute() const
{
if (Type.isTouched())
return 1;
return TechDraw::DrawViewPart::mustExecute();
}

void DrawProjGroupItem::onChanged(const App::Property *prop)
{
//TODO: Should we allow changes to the Type here? Seems that should be handled through DrawProjGroup
if (prop == &Type && Type.isTouched()) {
if (!isRestoring()) {
execute();
}
}

TechDraw::DrawViewPart::onChanged(prop);

}

DrawProjGroupItem::~DrawProjGroupItem()
{
}

void DrawProjGroupItem::onDocumentRestored()
{
setAutoPos(false); //if restoring from file, use X,Y from file, not auto!
execute();
}


PyObject *DrawProjGroupItem::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawProjGroupItemPy(this),true);
}
return Py::new_reference_to(PythonObject);
}

0 comments on commit 27ff991

Please sign in to comment.