From 3f5caa2181ea336d21020e1157662cae2ddfb0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Tue, 5 May 2015 17:17:45 +0200 Subject: [PATCH] group coordinate planes and lines --- src/App/Application.cpp | 2 + src/App/CMakeLists.txt | 2 + src/App/GeoFeatureGroupPyImp.cpp | 4 -- src/App/Line.h | 2 +- src/App/Origin.cpp | 54 +++++++++++++++++++++ src/App/Origin.h | 59 +++++++++++++++++++++++ src/Gui/Application.cpp | 2 + src/Gui/CMakeLists.txt | 2 + src/Gui/ViewProviderOrigin.cpp | 80 ++++++++++++++++++++++++++++++++ src/Gui/ViewProviderOrigin.h | 53 +++++++++++++++++++++ src/Gui/ViewProviderPart.cpp | 31 ++++++------- 11 files changed, 268 insertions(+), 23 deletions(-) create mode 100644 src/App/Origin.cpp create mode 100644 src/App/Origin.h create mode 100644 src/Gui/ViewProviderOrigin.cpp create mode 100644 src/Gui/ViewProviderOrigin.h diff --git a/src/App/Application.cpp b/src/App/Application.cpp index bce8fe0cd..b1e779123 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -98,6 +98,7 @@ #include "Plane.h" #include "Line.h" #include "Part.h" +#include "Origin.h" #include "MaterialObject.h" #include "Expression.h" @@ -1136,6 +1137,7 @@ void Application::initTypes(void) App ::Plane ::init(); App ::Line ::init(); App ::Part ::init(); + App ::Origin ::init(); // Expression classes App ::Expression ::init(); diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index b01a170fc..488bd3859 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -78,6 +78,7 @@ SET(Document_CPP_SRCS GeoFeatureGroupPyImp.cpp GeoFeatureGroup.cpp Part.cpp + Origin.cpp Path.cpp InventorObject.cpp MeasureDistance.cpp @@ -109,6 +110,7 @@ SET(Document_HPP_SRCS GeoFeature.h GeoFeatureGroup.h Part.h + Origin.h Path.h InventorObject.h MeasureDistance.h diff --git a/src/App/GeoFeatureGroupPyImp.cpp b/src/App/GeoFeatureGroupPyImp.cpp index 36e5e8dfc..d565576f3 100644 --- a/src/App/GeoFeatureGroupPyImp.cpp +++ b/src/App/GeoFeatureGroupPyImp.cpp @@ -52,10 +52,6 @@ PyObject* GeoFeatureGroupPy::addObject(PyObject *args) PyErr_SetString(PyExc_Exception, "Cannot add a GeoFeatureGroup to itself"); return NULL; } - if (docObj->getDocumentObjectPtr()->getTypeId().isDerivedFrom(GeoFeatureGroup::getClassTypeId())) { - PyErr_SetString(PyExc_Exception, "Cannot add a GeoFeatureGroup to a GeoFeatureGroup"); - return NULL; - } getGeoFeatureGroupPtr()->addObject(docObj->getDocumentObjectPtr()); diff --git a/src/App/Line.h b/src/App/Line.h index 0129f4edc..8c9463d7d 100644 --- a/src/App/Line.h +++ b/src/App/Line.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2012 * + * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/App/Origin.cpp b/src/App/Origin.cpp new file mode 100644 index 000000000..5d99520aa --- /dev/null +++ b/src/App/Origin.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * * + * 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_ +#endif + +#include +#include + +#include "Origin.h" + + +using namespace App; + + +PROPERTY_SOURCE(App::Origin, App::GeoFeatureGroup) + + + +//=========================================================================== +// Feature +//=========================================================================== + +Origin::Origin(void) +{ + +} + +Origin::~Origin(void) +{ +} + diff --git a/src/App/Origin.h b/src/App/Origin.h new file mode 100644 index 000000000..47039274e --- /dev/null +++ b/src/App/Origin.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * * + * 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 APP_Origin_H +#define APP_Origin_H + +#include "GeoFeatureGroup.h" +#include "PropertyLinks.h" + + + +namespace App +{ + + +/** Base class of all geometric document objects. + */ +class AppExport Origin : public App::GeoFeatureGroup +{ + PROPERTY_HEADER(App::Origin); + +public: + + /// Constructor + Origin(void); + virtual ~Origin(); + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "Gui::ViewProviderOrigin"; + } +}; + +//typedef App::FeaturePythonT OriginPython; + +} //namespace App + + +#endif // APP_Origin_H diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 393643b91..ca70ead7f 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -107,6 +107,7 @@ #include "ViewProviderPlane.h" #include "ViewProviderLine.h" #include "ViewProviderPart.h" +#include "ViewProviderOrigin.h" #include "ViewProviderMaterialObject.h" #include "Language/Translator.h" @@ -1546,6 +1547,7 @@ void Application::initTypes(void) Gui::ViewProviderPlane ::init(); Gui::ViewProviderLine ::init(); Gui::ViewProviderPart ::init(); + Gui::ViewProviderOrigin ::init(); Gui::ViewProviderMaterialObject ::init(); Gui::ViewProviderMaterialObjectPython ::init(); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 10af71678..01bbdf1d5 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -824,6 +824,7 @@ SET(Viewprovider_CPP_SRCS ViewProviderLine.cpp ViewProviderGeoFeatureGroup.cpp ViewProviderPart.cpp + ViewProviderOrigin.cpp ViewProviderMaterialObject.cpp ) SET(Viewprovider_SRCS @@ -845,6 +846,7 @@ SET(Viewprovider_SRCS ViewProviderLine.h ViewProviderGeoFeatureGroup.h ViewProviderPart.h + ViewProviderOrigin.h ViewProviderMaterialObject.h ) SOURCE_GROUP("View3D\\Viewprovider" FILES ${Viewprovider_SRCS}) diff --git a/src/Gui/ViewProviderOrigin.cpp b/src/Gui/ViewProviderOrigin.cpp new file mode 100644 index 000000000..18f80161b --- /dev/null +++ b/src/Gui/ViewProviderOrigin.cpp @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * * + * 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 +# include +#endif + +#include +#include +#include +#include + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include "ViewProviderOrigin.h" +#include "ViewProviderPlane.h" +#include "ViewProviderLine.h" +#include "Application.h" +#include "Command.h" +#include "BitmapFactory.h" +#include "Document.h" +#include "Tree.h" +#include "View3DInventor.h" +#include "View3DInventorViewer.h" + +#include "Base/Console.h" +#include +#include +#include + +using namespace Gui; + + +PROPERTY_SOURCE(Gui::ViewProviderOrigin, Gui::ViewProviderGeometryObject) + + +/** + * Creates the view provider for an object group. + */ +ViewProviderOrigin::ViewProviderOrigin() +{ + sPixmap = ":icon/delete.svg"; +} + +ViewProviderOrigin::~ViewProviderOrigin() +{ +} + +// Python feature ----------------------------------------------------------------------- + +namespace Gui { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderOriginPython, Gui::ViewProviderOrigin) +/// @endcond + +// explicit template instantiation +template class GuiExport ViewProviderPythonFeatureT; +} diff --git a/src/Gui/ViewProviderOrigin.h b/src/Gui/ViewProviderOrigin.h new file mode 100644 index 000000000..6d8b72c1a --- /dev/null +++ b/src/Gui/ViewProviderOrigin.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2015 * + * * + * 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 GUI_VIEWPROVIDER_ViewProviderOrigin_H +#define GUI_VIEWPROVIDER_ViewProviderOrigin_H + + +#include "ViewProviderGeoFeatureGroup.h" + +#include +#include + + + +namespace Gui { + +class GuiExport ViewProviderOrigin : public ViewProviderGeoFeatureGroup +{ + PROPERTY_HEADER(Gui::ViewProviderOrigin); + +public: + /// constructor. + ViewProviderOrigin(); + /// destructor. + virtual ~ViewProviderOrigin(); +}; + +typedef ViewProviderPythonFeatureT ViewProviderOriginPython; + +} // namespace Gui + +#endif // GUI_VIEWPROVIDER_DOCUMENTOBJECTGROUP_H + diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index 2cc3063ce..94eb475ec 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -235,45 +235,40 @@ void ViewProviderPart::setUpPart(const App::Part *part) if (!found) { // ... and put them in the 'Origin' group - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup = App.activeDocument().addObject('App::DocumentObjectGroup','%s')", "Origin"); - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup.Label = '%s'", QObject::tr("Origin").toStdString().c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"Origin = App.activeDocument().addObject('App::Origin','%s')", "Origin"); + Gui::Command::doCommand(Gui::Command::Doc,"Origin.Label = '%s'", QObject::tr("Origin").toStdString().c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(Origin)", part->getNameInDocument()); + // Add the planes ... Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[0]); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XY-Plane").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().ActiveObject)"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[1]); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)"); - + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().ActiveObject)"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[2]); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,1,1),120))"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().ActiveObject)"); // Add the lines ... Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", App::Part::BaselineTypes[0]); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("X-Axis").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().ActiveObject)"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", App::Part::BaselineTypes[1]); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,0,1),90))"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("Y-Axis").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - //Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)"); - + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().ActiveObject)"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", App::Part::BaselineTypes[2]); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("Z-Axis").toStdString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument()); - - //Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(OGroup)", part->getNameInDocument()); - // TODO: Fold the group (is that possible through the Python interface?) + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Origin.addObject(App.activeDocument().ActiveObject)"); + } }