Fix ProjectionGroupItem spacing

This commit is contained in:
WandererFan 2016-08-27 20:52:18 -04:00
parent 3901d2fe82
commit 27ff991d79
9 changed files with 637 additions and 625 deletions

View File

@ -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();
}
}
@ -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;
}
@ -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()) {
@ -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);

View File

@ -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);
}

View File

@ -1,223 +1,223 @@
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* 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>
# include <Standard_Failure.hxx>
#endif
#include <strstream>
#include <App/Application.h>
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Console.h>
#include "DrawView.h"
#include "DrawPage.h"
#include "DrawViewCollection.h"
#include "DrawViewClip.h"
#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml
using namespace TechDraw;
//===========================================================================
// DrawView
//===========================================================================
const char* DrawView::ScaleTypeEnums[]= {"Document",
"Automatic",
"Custom",
NULL};
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)");
ADD_PROPERTY_TYPE(Y ,(0),group,App::Prop_None,"Y position of the view on the page in modelling units (mm)");
ADD_PROPERTY_TYPE(Rotation ,(0),group,App::Prop_None,"Rotation of the view on the page in degrees counterclockwise");
ScaleType.setEnums(ScaleTypeEnums);
ADD_PROPERTY_TYPE(ScaleType,((long)0),group, App::Prop_None, "Scale Type");
ADD_PROPERTY_TYPE(Scale ,(1.0),group,App::Prop_None,"Scale factor of the view");
if (isRestoring()) {
autoPos = false;
}
}
DrawView::~DrawView()
{
}
App::DocumentObjectExecReturn *DrawView::execute(void)
{
TechDraw::DrawPage *page = findParentPage();
if(page) {
if (ScaleType.isValue("Document")) {
if(std::abs(page->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
Scale.setValue(page->Scale.getValue());
}
} else if (ScaleType.isValue("Automatic")) {
//check fit. if too big, rescale
if (!checkFit(page)) {
double newScale = autoScale(page->getPageWidth(),page->getPageHeight());
if(std::abs(newScale - Scale.getValue()) > FLT_EPSILON) { //stops onChanged/execute loop
Scale.setValue(newScale);
}
}
}
}
return App::DocumentObject::execute();
}
void DrawView::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if (prop == &Scale) {
execute();
} else if (prop == &ScaleType) {
if (ScaleType.isValue("Document")) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
} else if ( ScaleType.isValue("Custom") ) {
Scale.setStatus(App::Property::ReadOnly,false);
App::GetApplication().signalChangePropertyEditor(Scale);
} else if ( ScaleType.isValue("Automatic") ) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
}
execute();
} else if (prop == &X ||
prop == &Y) {
setAutoPos(false);
execute();
} else if (prop == &Rotation) {
execute();
}
}
App::DocumentObject::onChanged(prop);
}
////you must override this in derived class
QRectF DrawView::getRect() const
{
QRectF result(0,0,1,1);
return result;
}
void DrawView::onDocumentRestored()
{
// Rebuild the view
execute();
}
DrawPage* DrawView::findParentPage() const
{
// Get Feature Page
DrawPage *page = 0;
DrawViewCollection *collection = 0;
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) {
page = dynamic_cast<TechDraw::DrawPage *>(*it);
}
if ((*it)->getTypeId().isDerivedFrom(DrawViewCollection::getClassTypeId())) {
collection = dynamic_cast<TechDraw::DrawViewCollection *>(*it);
page = collection->findParentPage();
}
if(page)
break; // Found page so leave
}
return page;
}
bool DrawView::isInClip()
{
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawViewClip::getClassTypeId())) {
return true;
}
}
return false;
}
double DrawView::autoScale(double w, double h) const
{
double fudgeFactor = 0.90;
QRectF viewBox = getRect();
double xScale = w/viewBox.width();
double yScale = h/viewBox.height();
//find a standard scale that's close? 1:2, 1:10, 1:100...?
double newScale = fudgeFactor * std::min(xScale,yScale);
return newScale;
}
//!check if View fits on Page
bool DrawView::checkFit(TechDraw::DrawPage* p) const
{
bool result = true;
QRectF viewBox = getRect();
if ( (viewBox.width() > p->getPageWidth()) ||
(viewBox.height() > p->getPageHeight()) ) {
result = false;
}
return result;
}
PyObject *DrawView::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawViewPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
// Python Drawing feature ---------------------------------------------------------
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewPython, TechDraw::DrawView)
template<> const char* TechDraw::DrawViewPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderDrawingView";
}
/// @endcond
// explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawView>;
}
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* 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>
# include <Standard_Failure.hxx>
#endif
#include <strstream>
#include <App/Application.h>
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Console.h>
#include "DrawView.h"
#include "DrawPage.h"
#include "DrawViewCollection.h"
#include "DrawViewClip.h"
#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml
using namespace TechDraw;
//===========================================================================
// DrawView
//===========================================================================
const char* DrawView::ScaleTypeEnums[]= {"Document",
"Automatic",
"Custom",
NULL};
PROPERTY_SOURCE(TechDraw::DrawView, App::DocumentObject)
DrawView::DrawView(void)
: autoPos(true),
mouseMove(false)
{
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)");
ADD_PROPERTY_TYPE(Y ,(0),group,App::Prop_None,"Y position of the view on the page in modelling units (mm)");
ADD_PROPERTY_TYPE(Rotation ,(0),group,App::Prop_None,"Rotation of the view on the page in degrees counterclockwise");
ScaleType.setEnums(ScaleTypeEnums);
ADD_PROPERTY_TYPE(ScaleType,((long)0),group, App::Prop_None, "Scale Type");
ADD_PROPERTY_TYPE(Scale ,(1.0),group,App::Prop_None,"Scale factor of the view");
}
DrawView::~DrawView()
{
}
App::DocumentObjectExecReturn *DrawView::execute(void)
{
TechDraw::DrawPage *page = findParentPage();
if(page) {
if (ScaleType.isValue("Document")) {
if(std::abs(page->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
Scale.setValue(page->Scale.getValue());
}
} else if (ScaleType.isValue("Automatic")) {
//check fit. if too big, rescale
if (!checkFit(page)) {
double newScale = autoScale(page->getPageWidth(),page->getPageHeight());
if(std::abs(newScale - Scale.getValue()) > FLT_EPSILON) { //stops onChanged/execute loop
Scale.setValue(newScale);
}
}
}
}
return App::DocumentObject::execute();
}
void DrawView::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if (prop == &Scale) {
execute();
} else if (prop == &ScaleType) {
if (ScaleType.isValue("Document")) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
} else if ( ScaleType.isValue("Custom") ) {
Scale.setStatus(App::Property::ReadOnly,false);
App::GetApplication().signalChangePropertyEditor(Scale);
} else if ( ScaleType.isValue("Automatic") ) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
}
execute();
} else if (prop == &X ||
prop == &Y) {
if (isMouseMove()) {
setAutoPos(false); //should only be for manual changes? not programmatic changes?
}
execute();
} else if (prop == &Rotation) {
execute();
}
}
App::DocumentObject::onChanged(prop);
}
////you must override this in derived class
QRectF DrawView::getRect() const
{
QRectF result(0,0,1,1);
return result;
}
void DrawView::onDocumentRestored()
{
// Rebuild the view
execute();
}
DrawPage* DrawView::findParentPage() const
{
// Get Feature Page
DrawPage *page = 0;
DrawViewCollection *collection = 0;
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) {
page = dynamic_cast<TechDraw::DrawPage *>(*it);
}
if ((*it)->getTypeId().isDerivedFrom(DrawViewCollection::getClassTypeId())) {
collection = dynamic_cast<TechDraw::DrawViewCollection *>(*it);
page = collection->findParentPage();
}
if(page)
break; // Found page so leave
}
return page;
}
bool DrawView::isInClip()
{
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawViewClip::getClassTypeId())) {
return true;
}
}
return false;
}
double DrawView::autoScale(double w, double h) const
{
double fudgeFactor = 0.90;
QRectF viewBox = getRect();
double xScale = w/viewBox.width();
double yScale = h/viewBox.height();
//find a standard scale that's close? 1:2, 1:10, 1:100...?
double newScale = fudgeFactor * std::min(xScale,yScale);
return newScale;
}
//!check if View fits on Page
bool DrawView::checkFit(TechDraw::DrawPage* p) const
{
bool result = true;
QRectF viewBox = getRect();
if ( (viewBox.width() > p->getPageWidth()) ||
(viewBox.height() > p->getPageHeight()) ) {
result = false;
}
return result;
}
PyObject *DrawView::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new DrawViewPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
// Python Drawing feature ---------------------------------------------------------
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewPython, TechDraw::DrawView)
template<> const char* TechDraw::DrawViewPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderDrawingView";
}
/// @endcond
// explicit template instantiation
template class TechDrawExport FeaturePythonT<TechDraw::DrawView>;
}

View File

@ -1,92 +1,95 @@
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 *
* *
* 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 *
* *
***************************************************************************/
#ifndef _DrawView_h_
#define _DrawView_h_
#include <QRectF>
#include <App/DocumentObject.h>
#include <App/PropertyStandard.h>
#include <App/PropertyGeo.h>
#include <App/FeaturePython.h>
namespace TechDraw
{
class DrawPage;
/** Base class of all View Features in the drawing module
*/
class TechDrawExport DrawView : public App::DocumentObject
{
PROPERTY_HEADER(TechDraw::DrawView);
public:
/// Constructor
DrawView(void);
virtual ~DrawView();
App::PropertyFloat X;
App::PropertyFloat Y;
App::PropertyFloat Scale;
App::PropertyEnumeration ScaleType;
App::PropertyFloat Rotation;
/** @name methods overide Feature */
//@{
/// recalculate the Feature
virtual App::DocumentObjectExecReturn *execute(void);
virtual void onDocumentRestored();
//@}
bool isInClip();
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderDrawingView";
}
//return PyObject as DrawViewPy
virtual PyObject *getPyObject(void);
DrawPage* findParentPage() const;
bool allowAutoPos() {return autoPos;}; //sb in DPGI??
void setAutoPos(bool state) {autoPos = state;};
virtual QRectF getRect() const; //must be overridden by derived class
virtual double autoScale(double w, double h) const;
virtual bool checkFit(DrawPage*) const;
protected:
void onChanged(const App::Property* prop);
std::string pageFeatName;
bool autoPos;
private:
static const char* ScaleTypeEnums[];
};
typedef App::FeaturePythonT<DrawView> DrawViewPython;
} //namespace TechDraw
#endif
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 *
* *
* 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 *
* *
***************************************************************************/
#ifndef _DrawView_h_
#define _DrawView_h_
#include <QRectF>
#include <App/DocumentObject.h>
#include <App/PropertyStandard.h>
#include <App/PropertyGeo.h>
#include <App/FeaturePython.h>
namespace TechDraw
{
class DrawPage;
/** Base class of all View Features in the drawing module
*/
class TechDrawExport DrawView : public App::DocumentObject
{
PROPERTY_HEADER(TechDraw::DrawView);
public:
/// Constructor
DrawView(void);
virtual ~DrawView();
App::PropertyFloat X;
App::PropertyFloat Y;
App::PropertyFloat Scale;
App::PropertyEnumeration ScaleType;
App::PropertyFloat Rotation;
/** @name methods overide Feature */
//@{
/// recalculate the Feature
virtual App::DocumentObjectExecReturn *execute(void);
virtual void onDocumentRestored();
//@}
bool isInClip();
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderDrawingView";
}
//return PyObject as DrawViewPy
virtual PyObject *getPyObject(void);
DrawPage* findParentPage() const;
bool allowAutoPos() {return autoPos;}; //sb in DPGI??
void setAutoPos(bool state) {autoPos = state;};
bool isMouseMove() {return mouseMove;};
void setMouseMove(bool state) {mouseMove = state;};
virtual QRectF getRect() const; //must be overridden by derived class
virtual double autoScale(double w, double h) const;
virtual bool checkFit(DrawPage*) const;
protected:
void onChanged(const App::Property* prop);
std::string pageFeatName;
bool autoPos;
bool mouseMove;
private:
static const char* ScaleTypeEnums[];
};
typedef App::FeaturePythonT<DrawView> DrawViewPython;
} //namespace TechDraw
#endif

View File

@ -1,168 +1,165 @@
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* 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 <Base/Console.h>
#include <Base/Exception.h>
#include "DrawPage.h"
#include "DrawViewCollection.h"
using namespace TechDraw;
//===========================================================================
// DrawViewCollection
//===========================================================================
PROPERTY_SOURCE(TechDraw::DrawViewCollection, TechDraw::DrawView)
DrawViewCollection::DrawViewCollection()
{
static const char *group = "Drawing view";
ADD_PROPERTY_TYPE(Source ,(0), group, App::Prop_None,"Shape to view");
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Attached Views");
}
DrawViewCollection::~DrawViewCollection()
{
}
int DrawViewCollection::addView(DrawView *view)
{
// Add the new view to the collection
std::vector<App::DocumentObject *> newViews(Views.getValues());
newViews.push_back(view);
Views.setValues(newViews);
touch();
//TODO: also have to touch the parent page's views to get repaint??
DrawPage* page = findParentPage();
if (page) {
page->Views.touch();
}
return Views.getSize();
}
short DrawViewCollection::mustExecute() const
{
// If Tolerance Property is touched
if (Views.isTouched() ||
Source.isTouched()) {
return 1;
} else {
return TechDraw::DrawView::mustExecute();
}
}
int DrawViewCollection::countChildren()
{
//Count the children recursively if needed
int numChildren = 0;
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = dynamic_cast<App::DocumentObject *>(*it);
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) {
TechDraw::DrawViewCollection *viewCollection = dynamic_cast<TechDraw::DrawViewCollection *>(*it);
numChildren += viewCollection->countChildren() + 1;
} else {
numChildren += 1;
}
}
return numChildren;
}
void DrawViewCollection::onDocumentRestored()
{
// Rebuild the view
execute();
}
/// get called by the container when a Property was changed
void DrawViewCollection::onChanged(const App::Property* prop)
{
TechDraw::DrawView::onChanged(prop);
if (prop == &Source ||
prop == &Views){
if (!isRestoring()) {
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) {
TechDraw::DrawPage *page = static_cast<TechDraw::DrawPage *>(*it);
page->Views.touch();
}
}
}
}
}
App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
{
if (ScaleType.isValue("Document")) {
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
// Set scale factor of each view
view->ScaleType.setValue("Document");
view->touch();
}
}
} else if(strcmp(ScaleType.getValueAsString(), "Custom") == 0) {
// Rebuild the views
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
view->ScaleType.setValue("Custom");
// Set scale factor of each view
view->Scale.setValue(Scale.getValue());
view->touch();
}
}
}
return DrawView::execute();
}
QRectF DrawViewCollection::getRect() const
{
QRectF result;
for (auto& v:Views.getValues()) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(v);
result = result.united(view->getRect().translated(view->X.getValue(),view->Y.getValue()));
}
return QRectF(0,0,Scale.getValue() * result.width(),Scale.getValue() * result.height());
}
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* 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 <Base/Console.h>
#include <Base/Exception.h>
#include "DrawPage.h"
#include "DrawViewCollection.h"
using namespace TechDraw;
//===========================================================================
// DrawViewCollection
//===========================================================================
PROPERTY_SOURCE(TechDraw::DrawViewCollection, TechDraw::DrawView)
DrawViewCollection::DrawViewCollection()
{
static const char *group = "Drawing view";
ADD_PROPERTY_TYPE(Source ,(0), group, App::Prop_None,"Shape to view");
ADD_PROPERTY_TYPE(Views ,(0), group, App::Prop_None,"Attached Views");
}
DrawViewCollection::~DrawViewCollection()
{
}
int DrawViewCollection::addView(DrawView *view)
{
// Add the new view to the collection
std::vector<App::DocumentObject *> newViews(Views.getValues());
newViews.push_back(view);
Views.setValues(newViews);
touch();
//TODO: also have to touch the parent page's views to get repaint??
DrawPage* page = findParentPage();
if (page) {
page->Views.touch();
}
return Views.getSize();
}
short DrawViewCollection::mustExecute() const
{
// If Tolerance Property is touched
if (Views.isTouched() ||
Source.isTouched()) {
return 1;
} else {
return TechDraw::DrawView::mustExecute();
}
}
int DrawViewCollection::countChildren()
{
//Count the children recursively if needed
int numChildren = 0;
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = dynamic_cast<App::DocumentObject *>(*it);
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) {
TechDraw::DrawViewCollection *viewCollection = dynamic_cast<TechDraw::DrawViewCollection *>(*it);
numChildren += viewCollection->countChildren() + 1;
} else {
numChildren += 1;
}
}
return numChildren;
}
void DrawViewCollection::onDocumentRestored()
{
// Rebuild the view
execute();
}
void DrawViewCollection::onChanged(const App::Property* prop)
{
if (prop == &Views){
if (!isRestoring()) {
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawPage::getClassTypeId())) {
TechDraw::DrawPage *page = static_cast<TechDraw::DrawPage *>(*it);
page->Views.touch(); //touches page only, not my_views!
}
}
}
}
TechDraw::DrawView::onChanged(prop);
}
App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
{
if (ScaleType.isValue("Document")) {
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
// Set scale factor of each view
view->ScaleType.setValue("Document");
view->touch();
}
}
} else if(strcmp(ScaleType.getValueAsString(), "Custom") == 0) {
// Rebuild the views
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
view->ScaleType.setValue("Custom");
// Set scale factor of each view
view->Scale.setValue(Scale.getValue());
view->touch();
}
}
}
return DrawView::execute();
}
QRectF DrawViewCollection::getRect() const
{
QRectF result;
for (auto& v:Views.getValues()) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(v);
result = result.united(view->getRect().translated(view->X.getValue(),view->Y.getValue()));
}
return QRectF(0,0,Scale.getValue() * result.width(),Scale.getValue() * result.height());
}

View File

@ -139,7 +139,7 @@ QVariant QGIProjGroup::itemChange(GraphicsItemChange change, const QVariant &val
}
}
}
return QGIView::itemChange(change, value);
return QGIViewCollection::itemChange(change, value);
}
@ -183,7 +183,7 @@ void QGIProjGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f",
getViewObject()->getNameInDocument(), x());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f",
getViewObject()->getNameInDocument(), getY());// inverts Y
getViewObject()->getNameInDocument(), getY());// inverts Y
Gui::Command::commitCommand();
//Gui::Command::updateActive();
}
@ -224,4 +224,3 @@ void QGIProjGroup::drawBorder()
//QGIProjGroup does not have a border!
// Base::Console().Message("TRACE - QGIProjGroup::drawBorder - doing nothing!!\n");
}

View File

@ -100,9 +100,9 @@ void QGIView::alignTo(QGraphicsItem*item, const QString &alignment)
QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value)
{
QPointF newPos(0.0,0.0);
if(change == ItemPositionChange && scene()) {
QPointF newPos = value.toPointF();
newPos = value.toPointF();
if(locked){
newPos.setX(pos().x());
newPos.setY(pos().y());
@ -163,6 +163,7 @@ void QGIView::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
if(!locked && isSelected()) {
getViewObject()->setMouseMove(true);
if (!isInnerView()) {
double tempX = x(),
tempY = getY();
@ -172,6 +173,7 @@ void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
getViewObject()->X.setValue(x());
getViewObject()->Y.setValue(getYInClip(y()));
}
getViewObject()->setMouseMove(false);
}
QGraphicsItem::mouseReleaseEvent(event);
}

View File

@ -58,25 +58,16 @@ QGIViewCollection::QGIViewCollection()
QVariant QGIViewCollection::itemChange(GraphicsItemChange change, const QVariant &value)
{
return QGraphicsItemGroup::itemChange(change, value);
return QGIView::itemChange(change, value);
}
void QGIViewCollection::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
if(scene() && this == scene()->mouseGrabberItem()) {
Gui::Command::openCommand("Drag View Collection");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f",
getViewObject()->getNameInDocument(), x());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f",
getViewObject()->getNameInDocument(), getY());
Gui::Command::commitCommand();
//Gui::Command::updateActive();
}
QGraphicsItem::mouseReleaseEvent(event);
//TODO: should MouseMove logic go here instead of QGIView?
QGIView::mouseReleaseEvent(event);
}
void QGIViewCollection::updateView(bool update)
{
return QGIView::updateView(update);
}

View File

@ -102,18 +102,11 @@ void TaskProjGroup::viewToggled(bool toggle)
QString viewName = sender()->objectName();
int index = viewName.mid(7).toInt();
const char *viewNameCStr = viewChkIndexToCStr(index);
//Gui::Command::openCommand("Toggle orthographic view"); //TODO: Is this for undo?
if ( toggle && !multiView->hasProjection( viewNameCStr ) ) {
multiView->addProjection( viewNameCStr );
} else if ( !toggle && multiView->hasProjection( viewNameCStr ) ) {
multiView->removeProjection( viewNameCStr );
}
/// Called to notify the GUI that the scale has changed
Gui::Command::commitCommand();
Gui::Command::updateActive();
}
void TaskProjGroup::rotateButtonClicked(void)