OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup

This commit is contained in:
Alexander Golubev 2015-09-02 07:22:54 +03:00 committed by Stefan Tröger
parent 59ca9212d6
commit 2c2d155ee9
33 changed files with 835 additions and 557 deletions

View File

@ -76,7 +76,6 @@
#include <Base/UnitPy.h>
#include "GeoFeature.h"
#include "GeoFeatureGroup.h"
#include "FeatureTest.h"
#include "FeaturePython.h"
#include "ComplexGeoData.h"
@ -95,8 +94,10 @@
#include "Annotation.h"
#include "MeasureDistance.h"
#include "Placement.h"
#include "OriginFeature.h"
#include "GeoFeatureGroup.h"
#include "OriginGroup.h"
#include "Part.h"
#include "OriginFeature.h"
#include "Origin.h"
#include "MaterialObject.h"
#include "Expression.h"
@ -1122,8 +1123,6 @@ void Application::initTypes(void)
App ::Document ::init();
App ::DocumentObjectGroup ::init();
App ::DocumentObjectGroupPython ::init();
App ::GeoFeatureGroup ::init();
App ::GeoFeatureGroupPython ::init();
App ::DocumentObjectFileIncluded::init();
App ::InventorObject ::init();
App ::VRMLObject ::init();
@ -1136,6 +1135,9 @@ void Application::initTypes(void)
App ::OriginFeature ::init();
App ::Plane ::init();
App ::Line ::init();
App ::GeoFeatureGroup ::init();
App ::GeoFeatureGroupPython ::init();
App ::OriginGroup ::init();
App ::Part ::init();
App ::Origin ::init();

View File

@ -35,6 +35,7 @@ generate_from_xml(DocumentObjectPy)
generate_from_xml(DocumentObjectGroupPy)
generate_from_xml(GeoFeaturePy)
generate_from_xml(GeoFeatureGroupPy)
generate_from_xml(OriginGroupPy)
generate_from_xml(PartPy)
generate_from_xml(ComplexGeoDataPy)
@ -49,6 +50,7 @@ SET(FreeCADApp_XML_SRCS
DocumentObjectPy.xml
GeoFeaturePy.xml
GeoFeatureGroupPy.xml
OriginGroupPy.xml
PartPy.xml
DocumentPy.xml
PropertyContainerPy.xml
@ -65,7 +67,6 @@ SET(Document_CPP_SRCS
DocumentObjectFileIncluded.cpp
DocumentObjectGroup.cpp
DocumentObjectGroupPyImp.cpp
PartPyImp.cpp
GeoFeaturePyImp.cpp
DocumentObjectPyImp.cpp
DocumentObserver.cpp
@ -77,6 +78,9 @@ SET(Document_CPP_SRCS
GeoFeature.cpp
GeoFeatureGroupPyImp.cpp
GeoFeatureGroup.cpp
OriginGroupPyImp.cpp
OriginGroup.cpp
PartPyImp.cpp
Part.cpp
Origin.cpp
Path.cpp
@ -108,6 +112,7 @@ SET(Document_HPP_SRCS
FeatureTest.h
GeoFeature.h
GeoFeatureGroup.h
OriginGroup.h
Part.h
Origin.h
Path.h

View File

@ -60,14 +60,84 @@ void GeoFeatureGroup::transformPlacement(const Base::Placement &transform)
this->Placement.setValue(plm);
}
GeoFeatureGroup* GeoFeatureGroup::getGroupOfObject(const DocumentObject* obj)
std::vector<App::DocumentObject*> GeoFeatureGroup::getGeoSubObjects () const {
const auto & objs = Group.getValues();
std::set<const App::DocumentObjectGroup*> processedGroups;
std::set<App::DocumentObject*> rvSet;
std::set<App::DocumentObject*> curSearchSet (objs.begin(), objs.end());
processedGroups.insert ( this );
while ( !curSearchSet.empty() ) {
rvSet.insert ( curSearchSet.begin (), curSearchSet.end () );
std::set<App::DocumentObject*> nextSearchSet;
for ( auto obj: curSearchSet) {
if ( isNonGeoGroup (obj) ) {
const App::DocumentObjectGroup *grp = static_cast<const App::DocumentObjectGroup *> (obj);
// Check if we havent already processed the element may happen in case of nontree structure
// Note: if the condition is false this generally indicates malformed structure
if ( processedGroups.find (grp) == processedGroups.end() ) {
processedGroups.insert ( grp );
const auto & objs = grp->Group.getValues();
nextSearchSet.insert (objs.begin(), objs.end());
}
}
}
nextSearchSet.swap (curSearchSet);
}
return std::vector<App::DocumentObject*> ( rvSet.begin(), rvSet.end() );
}
bool GeoFeatureGroup::geoHasObject (const DocumentObject* obj) const {
const auto & objs = Group.getValues();
if (!obj) {
return false;
}
std::set<const App::DocumentObjectGroup*> processedGroups;
std::set<const App::DocumentObject*> curSearchSet (objs.begin(), objs.end());
processedGroups.insert ( this );
while ( !curSearchSet.empty() ) {
if ( curSearchSet.find (obj) != curSearchSet.end() ) {
return true;
}
std::set<const App::DocumentObject*> nextSearchSet;
for ( auto obj: curSearchSet) {
if ( isNonGeoGroup (obj) ) {
const App::DocumentObjectGroup *grp = static_cast<const App::DocumentObjectGroup *> (obj);
if ( processedGroups.find (grp) == processedGroups.end() ) {
processedGroups.insert ( grp );
const auto & objs = grp->Group.getValues();
nextSearchSet.insert (objs.begin(), objs.end());
}
}
}
nextSearchSet.swap (curSearchSet);
}
return false;
}
GeoFeatureGroup* GeoFeatureGroup::getGroupOfObject(const DocumentObject* obj, bool indirect)
{
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsOfType(GeoFeatureGroup::getClassTypeId());
for (std::vector<DocumentObject*>::const_iterator it = grps.begin(); it != grps.end(); ++it) {
GeoFeatureGroup* grp = (GeoFeatureGroup*)(*it);
if (grp->hasObject(obj))
return grp;
if ( indirect ) {
if (grp->geoHasObject(obj)) {
return grp;
}
} else {
if (grp->hasObject(obj)) {
return grp;
}
}
}
return 0;

View File

@ -46,8 +46,7 @@ public:
/**
* @brief transformPlacement applies transform to placement of this shape.
* Override this function to propagate the change of placement to base
* features, for example. By the time of writing this comment, the function
* was only called by alignment task (Edit->Alignment)
* features.
* @param transform (input).
*/
virtual void transformPlacement(const Base::Placement &transform);
@ -55,13 +54,28 @@ public:
GeoFeatureGroup(void);
virtual ~GeoFeatureGroup();
/// Returns all geometrically controlled objects: all objects of this group and it's non-geo subgroups
std::vector<App::DocumentObject*> getGeoSubObjects () const;
/// Returns true if either the group or one of it's non-geo subgroups has the object
bool geoHasObject (const DocumentObject* obj) const;
/** Returns the geo feature group which contains this object.
* In case this object is not part of any geoFeatureGroup 0 is returned.
* Unlike DocumentObjectGroup::getGroupOfObject serches only for GeoFeatureGroups
* @param obj the object to search for
* @param indirect if true return if the group that so-called geoHas the object, @see geoHasObject()
* default is true
*/
static GeoFeatureGroup* getGroupOfObject(const DocumentObject* obj);
static GeoFeatureGroup* getGroupOfObject(const DocumentObject* obj, bool indirect=true);
/// returns the type name of the ViewProvider
/// Returns true if the given DocumentObject is DocumentObjectGroup but not GeoFeatureGroup
static bool isNonGeoGroup(const DocumentObject* obj) {
return obj->isDerivedFrom ( App::DocumentObjectGroup::getClassTypeId () ) &&
!obj->isDerivedFrom ( App::GeoFeatureGroup::getClassTypeId () );
}
/// Returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "Gui::ViewProviderGeoFeatureGroup";
}

View File

@ -11,7 +11,7 @@
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>This class handles document objects in Part</UserDocu>
<UserDocu>This class handles placeable group of document objects</UserDocu>
</Documentation>
</PythonExport>

View File

@ -32,7 +32,7 @@
#include <Base/Placement.h>
#include <App/Document.h>
#include <App/OriginFeature.h>
#include "OriginFeature.h"
#include "Origin.h"
@ -123,7 +123,7 @@ App::DocumentObjectExecReturn *Origin::execute(void) {
setError ();
return new App::DocumentObjectExecReturn ( ex.what () );
}
// purgeError ();
return DocumentObject::execute ();
}

122
src/App/OriginGroup.cpp Normal file
View File

@ -0,0 +1,122 @@
/***************************************************************************
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 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 "OriginGroup.h"
#ifndef _PreComp_
#endif
#include <Base/Exception.h>
#include <App/Document.h>
#include "Origin.h"
#include "GeoFeature.h"
using namespace App;
PROPERTY_SOURCE(App::OriginGroup, App::GeoFeatureGroup);
OriginGroup::OriginGroup () {
ADD_PROPERTY_TYPE ( Origin, (0), 0, App::Prop_Hidden, "Origin linked to the group" );
}
OriginGroup::~OriginGroup ()
{ }
App::Origin *OriginGroup::getOrigin () const {
App::DocumentObject *originObj = Origin.getValue ();
if ( !originObj ) {
std::stringstream err;
err << "Can't find Origin for \"" << getNameInDocument () << "\"";
throw Base::Exception ( err.str().c_str () );
} else if (! originObj->isDerivedFrom ( App::Origin::getClassTypeId() ) ) {
std::stringstream err;
err << "Bad object \"" << originObj->getNameInDocument () << "\"(" << originObj->getTypeId().getName()
<< ") linked to the Origin of \"" << getNameInDocument () << "\"";
throw Base::Exception ( err.str().c_str () );
} else {
return static_cast<App::Origin *> ( originObj );
}
}
App::OriginGroup *OriginGroup::getGroupOfObject (const DocumentObject* obj, bool indirect) {
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsOfType ( OriginGroup::getClassTypeId() );
for (auto grpObj: grps) {
OriginGroup* grp = static_cast <OriginGroup* >(grpObj);
if ( indirect ) {
if ( grp->geoHasObject (obj) ) {
return grp;
}
} else {
if ( grp->hasObject (obj) ) {
return grp;
}
}
}
return 0;
}
short OriginGroup::mustExecute() const {
if (Origin.isTouched ()) {
return 1;
} else {
return GeoFeatureGroup::mustExecute();
}
}
App::DocumentObjectExecReturn *OriginGroup::execute() {
try { // try to find all base axis and planes in the origin
App::Origin *origin = getOrigin ();
} catch (const Base::Exception &ex) {
setError ();
return new App::DocumentObjectExecReturn ( ex.what () );
}
return GeoFeatureGroup::execute ();
}
void OriginGroup::setupObject () {
App::Document *doc = getDocument ();
std::string objName = std::string ( getNameInDocument()).append ( "Origin" );
App::DocumentObject *originObj = doc->addObject ( "App::Origin", objName.c_str () );
assert ( originObj && originObj->isDerivedFrom ( App::Origin::getClassTypeId () ) );
Origin.setValue (originObj);
GeoFeatureGroup::setupObject ();
}
void OriginGroup::unsetupObject () {
App::DocumentObject *origin = Origin.getValue ();
if (origin && !origin->isDeleting ()) {
origin->getDocument ()->remObject (origin->getNameInDocument());
}
GeoFeatureGroup::unsetupObject ();
}

76
src/App/OriginGroup.h Normal file
View File

@ -0,0 +1,76 @@
/***************************************************************************
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 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 ORIGINGROUP_H_QHTU73IF
#define ORIGINGROUP_H_QHTU73IF
#include "GeoFeatureGroup.h"
#include "PropertyLinks.h"
namespace App {
class Origin;
/**
* Represents an abstact placeable group of objects with an associated Origin
*/
class OriginGroup: public App::GeoFeatureGroup
{
PROPERTY_HEADER(App::OriginGroup);
public:
OriginGroup ();
virtual ~OriginGroup ();
/// Returns the origin link or throws an exception
App::Origin *getOrigin () const;
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName () const {
return "Gui::ViewProviderOriginGroup";
}
/**
* Returns the origin group which contains this object.
* In case this object is not part of any geoFeatureGroup 0 is returned.
* @param obj the object to search for
* @param indirect if true return if the group that so-called geoHas the object, @see geoHasObject()
* default is true
*/
static OriginGroup* getGroupOfObject (const DocumentObject* obj, bool indirect=true);
/// Returns true on changing OriginFeature set
virtual short mustExecute () const;
/// Origin linked to the group
PropertyLink Origin;
protected:
/// Checks integrity of the Origin
virtual App::DocumentObjectExecReturn *execute ();
/// Creates the corresponding Origin object
virtual void setupObject ();
/// Removes all planes and axis if they are still linked to the document
virtual void unsetupObject ();
};
} /* App */
#endif /* end of include guard: ORIGINGROUP_H_QHTU73IF */

19
src/App/OriginGroupPy.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeoFeatureGroupPy"
Name="OriginGroupPy"
Twin="OriginGroup"
TwinPointer="OriginGroup"
Include="App/OriginGroup.h"
Namespace="App"
FatherInclude="App/GeoFeatureGroupPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Alexander Golubev" EMail="fatzer2@gmail.com" />
<UserDocu>This class handles placable group of document objects with an Origin</UserDocu>
</Documentation>
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,34 @@
#include "PreCompiled.h"
#include "App/OriginGroup.h"
// inclusion of the generated files (generated out of OriginGroupPy.xml)
#include "OriginGroupPy.h"
#include "OriginGroupPy.cpp"
using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string OriginGroupPy::representation(void) const
{
return std::string("<OriginGroup object>");
}
PyObject *OriginGroupPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int OriginGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@ -35,18 +35,14 @@
using namespace App;
PROPERTY_SOURCE(App::Part, App::GeoFeatureGroup)
PROPERTY_SOURCE(App::Part, App::OriginGroup)
//===========================================================================
// Feature
// Part
//===========================================================================
const char* Part::BaseplaneTypes[3] = {"XY_Plane", "XZ_Plane", "YZ_Plane"};
const char* Part::BaselineTypes[3] = {"X_Axis", "Y_Axis", "Z_Axis"};
Part::Part(void)
{
ADD_PROPERTY(Type,(""));

View File

@ -24,7 +24,7 @@
#ifndef APP_Part_H
#define APP_Part_H
#include "GeoFeatureGroup.h"
#include "OriginGroup.h"
#include "PropertyLinks.h"
@ -35,7 +35,7 @@ namespace App
/** Base class of all geometric document objects.
*/
class AppExport Part : public App::GeoFeatureGroup
class AppExport Part : public App::OriginGroup
{
PROPERTY_HEADER(App::Part);
@ -75,7 +75,6 @@ public:
App::PropertyColor Color;
//@}
/// Constructor
Part(void);
virtual ~Part();
@ -85,11 +84,7 @@ public:
return "Gui::ViewProviderPart";
}
virtual PyObject *getPyObject(void);
static const char* BaseplaneTypes[3];
static const char* BaselineTypes[3];
};
//typedef App::FeaturePythonT<Part> PartPython;

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeoFeatureGroupPy"
Father="OriginGroupPy"
Name="PartPy"
Twin="Part"
TwinPointer="Part"
Include="App/Part.h"
Namespace="App"
FatherInclude="App/GeoFeatureGroupPy.h"
FatherInclude="App/OriginGroupPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />

View File

@ -98,7 +98,6 @@
#include "ViewProviderPythonFeature.h"
#include "ViewProviderDocumentObjectGroup.h"
#include "ViewProviderGeometryObject.h"
#include "ViewProviderGeoFeatureGroup.h"
#include "ViewProviderInventorObject.h"
#include "ViewProviderVRMLObject.h"
#include "ViewProviderAnnotation.h"
@ -106,6 +105,8 @@
#include "ViewProviderPlacement.h"
#include "ViewProviderPlane.h"
#include "ViewProviderLine.h"
#include "ViewProviderGeoFeatureGroup.h"
#include "ViewProviderOriginGroup.h"
#include "ViewProviderPart.h"
#include "ViewProviderOrigin.h"
#include "ViewProviderMaterialObject.h"
@ -1533,8 +1534,6 @@ void Application::initTypes(void)
Gui::ViewProviderDocumentObjectGroup ::init();
Gui::ViewProviderDocumentObjectGroupPython ::init();
Gui::ViewProviderGeometryObject ::init();
Gui::ViewProviderGeoFeatureGroup ::init();
Gui::ViewProviderGeoFeatureGroupPython ::init();
Gui::ViewProviderInventorObject ::init();
Gui::ViewProviderVRMLObject ::init();
Gui::ViewProviderAnnotation ::init();
@ -1546,6 +1545,9 @@ void Application::initTypes(void)
Gui::ViewProviderPlacement ::init();
Gui::ViewProviderPlane ::init();
Gui::ViewProviderLine ::init();
Gui::ViewProviderGeoFeatureGroup ::init();
Gui::ViewProviderGeoFeatureGroupPython ::init();
Gui::ViewProviderOriginGroup ::init();
Gui::ViewProviderPart ::init();
Gui::ViewProviderOrigin ::init();
Gui::ViewProviderMaterialObject ::init();

View File

@ -837,6 +837,7 @@ SET(Viewprovider_CPP_SRCS
ViewProviderPlane.cpp
ViewProviderLine.cpp
ViewProviderGeoFeatureGroup.cpp
ViewProviderOriginGroup.cpp
ViewProviderPart.cpp
ViewProviderOrigin.cpp
ViewProviderMaterialObject.cpp
@ -859,6 +860,7 @@ SET(Viewprovider_SRCS
ViewProviderPlane.h
ViewProviderLine.h
ViewProviderGeoFeatureGroup.h
ViewProviderOriginGroup.h
ViewProviderPart.h
ViewProviderOrigin.h
ViewProviderMaterialObject.h

View File

@ -51,41 +51,13 @@ ViewProviderGeoFeatureGroup::~ViewProviderGeoFeatureGroup()
}
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroup::claimChildren3D(void) const {
App::GeoFeatureGroup *geoGroup = static_cast<App::GeoFeatureGroup *>(getObject());
const auto & objs = geoGroup->Group.getValues();
std::set<App::DocumentObject*> rvSet;
// search recursively for all non-geoGroups and claim their children either
std::set<App::DocumentObject*> curSearchSet (objs.begin(), objs.end());
for ( auto objIt = curSearchSet.begin(); !curSearchSet.empty();
curSearchSet.erase (objIt), objIt = curSearchSet.begin() ) {
// Check if we havent already processed the element may happen in case of nontree structure
// Note: this case generally indicates malformed structure
if ( rvSet.find (*objIt) != rvSet.end() ) {
continue;
}
rvSet.insert (*objIt);
if ( (*objIt)->isDerivedFrom ( App::DocumentObjectGroup::getClassTypeId () ) &&
!(*objIt)->isDerivedFrom ( App::GeoFeatureGroup::getClassTypeId () ) ) {
// add the non-GeoGroup's content to search
App::DocumentObjectGroup *group = static_cast<App::DocumentObjectGroup *> (*objIt);
const auto & objs = group->Group.getValues();
curSearchSet.insert ( objs.begin(), objs.end() );
}
}
return std::vector<App::DocumentObject*> ( rvSet.begin(), rvSet.end() );
return static_cast<App::GeoFeatureGroup *>(getObject())->getGeoSubObjects ();
}
void ViewProviderGeoFeatureGroup::attach(App::DocumentObject* pcObject)
{
addDisplayMaskMode(pcGroupChildren, "Group");
Gui::ViewProviderDocumentObjectGroup::attach(pcObject);
addDisplayMaskMode(pcGroupChildren, "Group");
}
void ViewProviderGeoFeatureGroup::setDisplayMode(const char* ModeName)

View File

@ -0,0 +1,178 @@
/***************************************************************************
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 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 <Inventor/actions/SoGetBoundingBoxAction.h>
# include <Inventor/nodes/SoSeparator.h>
# include <boost/bind.hpp>
#endif
#include <Base/Console.h>
#include <App/OriginGroup.h>
#include <App/Origin.h>
#include "Application.h"
#include "Document.h"
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#include "ViewProviderOrigin.h"
#include "ViewProviderOriginGroup.h"
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderOriginGroup, Gui::ViewProviderGeoFeatureGroup)
ViewProviderOriginGroup::ViewProviderOriginGroup ()
{ }
ViewProviderOriginGroup::~ViewProviderOriginGroup () {
connectChangedObjectApp.disconnect();
connectChangedObjectGui.disconnect();
}
std::vector<App::DocumentObject*> ViewProviderOriginGroup::constructChildren (
const std::vector<App::DocumentObject*> &children ) const
{
App::OriginGroup *group = static_cast <App::OriginGroup *> ( getObject() );
App::DocumentObject *originObj = group->Origin.getValue();
// Origin must be first
if (originObj) {
std::vector<App::DocumentObject*> rv;
rv.push_back (originObj);
std::copy (children.begin(), children.end(), std::back_inserter (rv));
return rv;
} else { // Generally shouldn't happen but must be handled in case origin is lost
return children;
}
}
std::vector<App::DocumentObject*> ViewProviderOriginGroup::claimChildren () const {
return constructChildren ( ViewProviderGeoFeatureGroup::claimChildren () );
}
std::vector<App::DocumentObject*> ViewProviderOriginGroup::claimChildren3D () const {
return constructChildren ( ViewProviderGeoFeatureGroup::claimChildren3D () );
}
void ViewProviderOriginGroup::attach(App::DocumentObject *pcObject) {
ViewProviderGeoFeatureGroup::attach ( pcObject );
App::Document *adoc = pcObject->getDocument ();
Gui::Document *gdoc = Gui::Application::Instance->getDocument ( adoc ) ;
assert ( adoc );
assert ( gdoc );
connectChangedObjectApp = adoc->signalChangedObject.connect (
boost::bind ( &ViewProviderOriginGroup::slotChangedObjectApp, this, _1) );
connectChangedObjectGui = gdoc->signalChangedObject.connect (
boost::bind ( &ViewProviderOriginGroup::slotChangedObjectGui, this, _1) );
}
void ViewProviderOriginGroup::updateData ( const App::Property* prop ) {
App::OriginGroup *group = static_cast<App::OriginGroup*> ( getObject() );
if ( group && prop == &group->Group ) {
updateOriginSize();
}
ViewProviderGeoFeatureGroup::updateData ( prop );
}
void ViewProviderOriginGroup::slotChangedObjectApp ( const App::DocumentObject& obj) {
App::OriginGroup *group = static_cast<App::OriginGroup*> ( getObject() );
if ( group && group->hasObject (&obj, /*recusive=*/ true ) ) {
updateOriginSize ();
}
}
void ViewProviderOriginGroup::slotChangedObjectGui ( const Gui::ViewProviderDocumentObject& vp) {
if ( !vp.isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) ) {
// Ignore origins to avoid infinite recursion (not likely in a well-formed focument,
// but may happen in documents designed in old versions of assembly branch )
App::OriginGroup *group = static_cast<App::OriginGroup*> ( getObject() );
App::DocumentObject *obj = vp.getObject ();
if ( group && obj && group->hasObject (obj, /*recusive=*/ true ) ) {
updateOriginSize ();
}
}
}
void ViewProviderOriginGroup::updateOriginSize () {
App::OriginGroup* group = static_cast<App::OriginGroup*> ( getObject() );
// obtain an Origin and it's ViewProvider
App::Origin* origin = 0;
Gui::ViewProviderOrigin* vpOrigin = 0;
try {
origin = group->getOrigin ();
assert (origin);
Gui::ViewProvider *vp = Gui::Application::Instance->getViewProvider(origin);
if (!vp) {
throw Base::Exception ("No view provider linked to the Origin");
}
assert ( vp->isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) );
vpOrigin = static_cast <Gui::ViewProviderOrigin *> ( vp );
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what() );
return;
}
View3DInventorViewer* viewer = static_cast<View3DInventor*>(this->getActiveView())->getViewer();
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
// calculate the bounding box for out content
SbBox3f bbox(0,0,0, 0,0,0);
for(App::DocumentObject* obj : group->getGeoSubObjects()) {
ViewProvider *vp = Gui::Application::Instance->getViewProvider(obj);
if (!vp) {
continue;
}
bboxAction.apply ( vp->getRoot () );
bbox.extendBy ( bboxAction.getBoundingBox () );
};
// get the bounding box values
SbVec3f max = bbox.getMax();
SbVec3f min = bbox.getMin();
Base::Vector3d size;
for (uint_fast8_t i=0; i<3; i++) {
size[i] = std::max ( fabs ( max[i] ), fabs ( min[i] ) );
if (size[i] < 1e-7) { // TODO replace the magic values (2015-08-31, Fat-Zer)
size[i] = ViewProviderOrigin::defaultSize();
}
}
vpOrigin->Size.setValue ( size * 1.3 );
}

View File

@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (c) Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> 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 VIEWPROVIDERORIGINGROUP_H_JIXBOPA7
#define VIEWPROVIDERORIGINGROUP_H_JIXBOPA7
#include <boost/signals.hpp>
#include "ViewProviderGeoFeatureGroup.h"
namespace Gui {
class GuiExport ViewProviderOriginGroup: public ViewProviderGeoFeatureGroup
{
PROPERTY_HEADER(Gui::ViewProviderOriginGroup);
public:
ViewProviderOriginGroup ();
virtual ~ViewProviderOriginGroup ();
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
virtual void attach(App::DocumentObject *pcObject);
virtual void updateData(const App::Property* prop);
void updateOriginSize();
protected:
void slotChangedObjectApp ( const App::DocumentObject& obj );
void slotChangedObjectGui ( const Gui::ViewProviderDocumentObject& obj );
private:
std::vector<App::DocumentObject*> constructChildren (
const std::vector<App::DocumentObject*> &children ) const;
boost::signals::connection connectChangedObjectApp;
boost::signals::connection connectChangedObjectGui;
};
} /* Gui */
#endif /* end of include guard: VIEWPROVIDERORIGINGROUP_H_JIXBOPA7 */

View File

@ -29,161 +29,55 @@
#endif
#include <App/Part.h>
#include <App/Origin.h>
#include <App/OriginFeature.h>
#include <App/Document.h>
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include "ViewProviderPart.h"
#include "ViewProviderOrigin.h"
#include "ViewProviderPlane.h"
#include "ViewProviderLine.h"
#include "Application.h"
#include "Command.h"
#include "ActiveObjectList.h"
#include "BitmapFactory.h"
#include "Document.h"
#include "Tree.h"
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#include "Command.h"
#include "ViewProviderPart.h"
#include "Base/Console.h"
#include <boost/bind.hpp>
#include <Inventor/actions/SoGetBoundingBoxAction.h>
#include <Inventor/nodes/SoSeparator.h>
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderPart, Gui::ViewProviderGeoFeatureGroup)
PROPERTY_SOURCE(Gui::ViewProviderPart, Gui::ViewProviderOriginGroup)
/**
* Creates the view provider for an object group.
*/
ViewProviderPart::ViewProviderPart()
{
ADD_PROPERTY(Workbench,("PartDesignWorkbench"));
}
{ }
ViewProviderPart::~ViewProviderPart()
{
connection.disconnect();
}
{ }
/**
* TODO
* Whenever a property of the group gets changed then the same property of all
* associated view providers of the objects of the object group get changed as well.
*/
void ViewProviderPart::onChanged(const App::Property* prop)
{
ViewProviderGeoFeatureGroup::onChanged(prop);
void ViewProviderPart::onChanged(const App::Property* prop) {
ViewProviderOriginGroup::onChanged(prop);
}
void ViewProviderPart::attach(App::DocumentObject *pcObj)
{
connection = pcObj->getDocument()->signalChangedObject.connect(boost::bind(&ViewProviderPart::onObjectChanged, this, _1, _2));
ViewProviderGeoFeatureGroup::attach(pcObj);
}
void ViewProviderPart::updateData(const App::Property* prop)
{
ViewProviderGeoFeatureGroup::updateData(prop);
}
void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App::Property&)
{
Gui::Document* gdoc = Gui::Application::Instance->getDocument ( getObject()->getDocument() );
App::Part* part = static_cast<App::Part*>(pcObject);
if ( &obj == pcObject || (
obj.getTypeId() != App::Origin::getClassTypeId() &&
obj.getTypeId() != App::Plane::getClassTypeId() &&
obj.getTypeId() != App::Line::getClassTypeId() ) ) {
View3DInventorViewer* viewer = static_cast<View3DInventor*>(this->getActiveView())->getViewer();
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
//calculate for everything but datums
SbBox3f bbox(1e-9, 1e-9, 1e-9, 1e-9, 1e-9, 1e-9);
for(App::DocumentObject* obj : part->getObjects()) {
if(obj->getTypeId() != App::Origin::getClassTypeId() &&
obj->getTypeId() != App::Plane::getClassTypeId() &&
obj->getTypeId() != App::Line::getClassTypeId() ) {
//getting crash on deletion PartDesign::Body object. no viewprovider.
ViewProvider *viewProvider = Gui::Application::Instance->getViewProvider(obj);
if (!viewProvider)
continue;
bboxAction.apply(viewProvider->getRoot());
bbox.extendBy(bboxAction.getBoundingBox());
}
};
//get the bounding box values
SbVec3f max = bbox.getMax();
SbVec3f min = bbox.getMin();
auto origins = part->getObjectsOfType(App::Origin::getClassTypeId());
if (origins.empty())
return;
App::Origin* origin = dynamic_cast<App::Origin*>(origins.front());
if(!origin)
return;
Base::Vector3d size;
for (uint_fast8_t i=0; i<3; i++) {
size[i] = std::max ( fabs ( max[i] ), fabs ( min[i] ) );
if (size[i] < 1e-7) { // TODO replace it with some non-magick value (2015-08-31, Fat-Zer)
size[i] = ViewProviderOrigin::defaultSize();
}
}
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(origin);
if (vp) {
assert ( vp->isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) );
Gui::ViewProviderOrigin *vpOrigin = static_cast<Gui::ViewProviderOrigin *> (vp);
vpOrigin->Size.setValue ( size * 1.3 );
}
}
}
bool ViewProviderPart::doubleClicked(void)
{
if(Workbench.getStrValue() != "") {
// assure the given workbench
Gui::Command::assureWorkbench( Workbench.getValue() );
}
//make the part the active one
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, this->getObject()->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Gui,
"Gui.activeView().setActiveObject('%s', App.activeDocument().%s)",
PARTKEY, this->getObject()->getNameInDocument());
return true;
}
// commented out for thurther rewrite (2015-09-01, Fat-Zer)
// bool ViewProviderPart::onDelete(const std::vector<std::string> &)
// {
// if(getActiveView()->getActiveObject<App::Part*>(PARTKEY) == getObject())
// Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', None)", PARTKEY);
//
// return true;
// }
void ViewProviderPart::Restore(Base::XMLReader &reader)
{
Visibility.StatusBits.set(9); // tmp. set
ViewProviderDocumentObject::Restore(reader);
Visibility.StatusBits.reset(9); // unset
}
/**
* Returns the pixmap for the list item.
*/
QIcon ViewProviderPart::getIcon() const
{
// TODO Make a nice icon for the part (2015-09-01, Fat-Zer)
QIcon groupIcon;
groupIcon.addPixmap(QApplication::style()->standardPixmap(QStyle::SP_DirClosedIcon),
QIcon::Normal, QIcon::Off);
@ -192,21 +86,6 @@ QIcon ViewProviderPart::getIcon() const
return groupIcon;
}
void ViewProviderPart::setUpPart(const App::Part *part)
{
// add the origin at the root of the Part
// first check if they already exist
std::vector<App::DocumentObject*> origins = part->getObjectsOfType(App::Origin::getClassTypeId());
if ( origins.empty() ) {
std::string oname = part->getDocument()->getUniqueObjectName("Origin");
Gui::Command::doCommand(Gui::Command::Doc,"Origin = App.activeDocument().addObject('App::Origin','%s')", oname.c_str());
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());
}
}
// Python feature -----------------------------------------------------------------------
namespace Gui {

View File

@ -25,17 +25,13 @@
#define GUI_VIEWPROVIDER_ViewProviderPart_H
#include "ViewProviderGeoFeatureGroup.h"
#include "ViewProviderOriginGroup.h"
#include "ViewProviderPythonFeature.h"
#include <App/PropertyStandard.h>
#include <App/Part.h>
namespace Gui {
class GuiExport ViewProviderPart : public ViewProviderGeoFeatureGroup
class GuiExport ViewProviderPart : public ViewProviderOriginGroup
{
PROPERTY_HEADER(Gui::ViewProviderPart);
@ -45,29 +41,12 @@ public:
/// destructor.
virtual ~ViewProviderPart();
/// Name of the workbench which created that Part
App::PropertyString Workbench;
void attach(App::DocumentObject *pcObject);
void updateData(const App::Property*);
void Restore(Base::XMLReader &reader);
QIcon getIcon(void) const;
/// returns a list of all possible modes
virtual bool doubleClicked(void);
// virtual bool onDelete(const std::vector<std::string> &);
/// helper to set up the standard content of a Part Object
static void setUpPart(const App::Part *part);
protected:
/// get called by the container whenever a property has been changed
void onChanged(const App::Property* prop);
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;
void onObjectChanged(const App::DocumentObject&, const App::Property&);
private:
boost::signals::connection connection;
virtual void onChanged(const App::Property* prop);
};
typedef ViewProviderPythonFeatureT<ViewProviderPart> ViewProviderPartPython;

View File

@ -79,25 +79,6 @@
// return PartDesignGui::ActivePartObject->getPyObject();
//}
void setUpPart(App::Part *part);
static PyObject * setUpPart(PyObject *self, PyObject *args)
{
PyObject *object=0;
if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) )
return NULL;
App::Part* part = static_cast<App::PartPy*>(object)->getPartPtr();
// Should be set!
assert(part);
PartDesignGui::setUpPart(part);
Py_Return;
}
/* registration table */
struct PyMethodDef Assembly_methods[] = {
//{"setActiveBody" ,setActiveBody ,METH_VARARGS,
@ -106,8 +87,5 @@ struct PyMethodDef Assembly_methods[] = {
//{"getActiveBody" ,getActiveBody ,METH_NOARGS,
// "getActiveBody() -- Get the PartBody object in work."},
{"setUpPart" ,setUpPart ,METH_VARARGS,
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
{NULL, NULL} /* end of table marker */
};

View File

@ -38,54 +38,9 @@
#include <Mod/PartDesign/App/BodyPy.h>
#include "ViewProviderBody.h"
#include "Workbench.h"
#include "Utils.h"
namespace PartDesignGui {
// The names of the base planes. Note: The user-visible label is different from this
const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"};
}
<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp
static PyObject * setActiveBody(PyObject *self, PyObject *args)
{
PyObject *object=0;
if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
PartDesign::Body* Item = static_cast<PartDesign::BodyPy*>(object)->getBodyPtr();
// Should be set!
assert(Item);
// Set old body inactive if we are activating another body in the same document
if ((PartDesignGui::ActivePartObject != NULL) &&
(PartDesignGui::ActivePartObject->getDocument() == Item->getDocument()))
PartDesignGui::ActivePartObject->IsActive.setValue(false);
PartDesignGui::ActivePartObject = Item;
PartDesignGui::ActiveAppDoc = Item->getDocument();
PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc);
PartDesignGui::ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*> (PartDesignGui::ActiveGuiDoc->getViewProvider(Item));
PartDesignGui::ActiveVp->show();
Item->IsActive.setValue(true);
} else {
// This handles the case of deactivating the workbench
PartDesignGui::ActivePartObject=0;
PartDesignGui::ActiveGuiDoc =0;
PartDesignGui::ActiveAppDoc =0;
PartDesignGui::ActiveVp =0;
}
Py_Return;
}
static PyObject * getActiveBody(PyObject *, PyObject *)
{
if (PartDesignGui::ActivePartObject == NULL) {
return Py::_None();
}
return PartDesignGui::ActivePartObject->getPyObject();
}
=======
//static PyObject * setActiveBody(PyObject *self, PyObject *args)
//{
// PyObject *object=0;
@ -123,43 +78,21 @@ static PyObject * getActiveBody(PyObject *, PyObject *)
//
// return PartDesignGui::ActivePartObject->getPyObject();
//}
>>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
void setUpPart(App::Part *part);
static PyObject * setUpPart(PyObject *self, PyObject *args)
{
PyObject *object=0;
if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) )
return NULL;
App::Part* part = static_cast<App::PartPy*>(object)->getPartPtr();
// Should be set!
assert(part);
PartDesignGui::Workbench::setUpPart(part);
Py_Return;
}
/* registration table */
<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp
struct PyMethodDef Assembly_methods[] = {
{"setActiveBody" ,setActiveBody ,METH_VARARGS,
"setActiveBody(BodyObject) -- Set the PartBody object in work."},
=======
struct PyMethodDef PartDesignGui_Import_methods[] = {
//{"setActiveBody" ,setActiveBody ,METH_VARARGS,
// "setActiveBody(BodyObject) -- Set the PartBody object in work."},
>>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
//{"getActiveBody" ,getActiveBody ,METH_NOARGS,
// "getActiveBody() -- Get the PartBody object in work."},
<<<<<<< f03c0f9bdef9886ee45a086b02fa7ebaa99b6825:src/Mod/Assembly/App/AppAssemblyPy.cpp
{"setUpPart" ,setUpPart ,METH_VARARGS,
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
{NULL, NULL} /* end of table marker */
=======
{NULL, NULL} /* end of table marker */
>>>>>>> OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
};

View File

@ -35,6 +35,7 @@
#include <algorithm>
#include <App/DocumentObjectGroup.h>
#include <App/Origin.h>
#include <App/OriginFeature.h>
#include <App/Part.h>
#include <Gui/Application.h>
@ -43,7 +44,7 @@
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/Document.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Body.h>
@ -236,7 +237,7 @@ CmdPartDesignNewSketch::CmdPartDesignNewSketch()
void CmdPartDesignNewSketch::activated(int iMsg)
{
App::Document *doc = getDocument ();
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(
/*messageIfNot = */ PartDesignGui::assureModernWorkflow ( doc ) );
// No PartDesign feature without Body past FreeCAD 0.13
@ -307,18 +308,8 @@ void CmdPartDesignNewSketch::activated(int iMsg)
}
if (!pcActiveBody->hasFeature(obj)) {
// TODO check what the heck is going on here (2015-08-31, Fat-Zer)
bool isBasePlane = false;
if(obj->isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* pfeat = static_cast<App::Plane*>(obj);
for (unsigned i = 0; i < 3; i++) {
if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) {
isBasePlane = true;
break;
}
}
}
if (!isBasePlane) {
if ( !obj->isDerivedFrom ( App::Plane::getClassTypeId() ) ) {
// TODO check here if the plane associated with right part/body (2015-09-01, Fat-Zer)
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from other body"),
QObject::tr("You have to select a face or plane from the active body!"));
return;
@ -346,55 +337,48 @@ void CmdPartDesignNewSketch::activated(int iMsg)
}
else {
// Get a valid plane from the user
std::vector<PartDesignGui::TaskFeaturePick::featureStatus> status;
std::vector<App::DocumentObject*> planes = getDocument()->getObjectsOfType(App::Plane::getClassTypeId());
std::vector<App::DocumentObject*> planestmp = getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId());
planes.insert(planes.end(), planestmp.begin(), planestmp.end());
unsigned validPlanes = 0;
std::vector<App::DocumentObject*>::const_iterator firstValidPlane = planes.end();
App::Part* pcActivePart = Gui::Application::Instance->activeView()->getActiveObject<App::Part*>(PARTKEY);
for (std::vector<App::DocumentObject*>::iterator p = planes.begin(); p != planes.end(); p++) {
// Check whether this plane is a base plane
bool base = false;
if((*p)->isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* pfeat = static_cast<App::Plane*>(*p);
for (unsigned i = 0; i < 3; i++) {
if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) {
if(pcActivePart->hasObject(pfeat, true))
status.push_back(PartDesignGui::TaskFeaturePick::basePlane);
else
status.push_back(PartDesignGui::TaskFeaturePick::invalidShape);
if (firstValidPlane == planes.end())
firstValidPlane = p;
validPlanes++;
base = true;
break;
}
std::vector<App::DocumentObject*> planes;
std::vector<PartDesignGui::TaskFeaturePick::featureStatus> status;
// Baseplanes are preaprooved
if ( pcActivePart ) {
try {
for ( auto plane: pcActivePart->getOrigin ()->planes() ) {
planes.push_back (plane);
status.push_back(PartDesignGui::TaskFeaturePick::basePlane);
validPlanes++;
}
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what() );
}
if (base) continue;
}
std::vector<App::DocumentObject*> datumPlanes =
getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId());
for (auto plane: datumPlanes) {
planes.push_back ( plane );
// Check whether this plane belongs to the active body
if (!pcActiveBody->hasFeature(*p)) {
if(pcActivePart->hasObject(*p, true))
if (!pcActiveBody->hasFeature(plane)) {
if ( pcActivePart && pcActivePart->hasObject ( plane, true ) ) {
status.push_back(PartDesignGui::TaskFeaturePick::otherBody);
else
} else {
status.push_back(PartDesignGui::TaskFeaturePick::otherPart);
}
continue;
} else {
if (pcActiveBody->isAfterInsertPoint(*p)) {
if (pcActiveBody->isAfterInsertPoint ( plane ) ) {
status.push_back(PartDesignGui::TaskFeaturePick::afterTip);
continue;
}
}
// All checks passed - found a valid plane
if (firstValidPlane == planes.end())
firstValidPlane = p;
validPlanes++;
status.push_back(PartDesignGui::TaskFeaturePick::validFeature);
}
@ -1409,10 +1393,11 @@ void CmdPartDesignMirrored::activated(int iMsg)
Gui::Command::doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaseplaneTypes[0]);
}
// TODO Check if default mirrored plane correctly set (2015-09-01, Fat-Zer)
// else {
// doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
// App::Part::BaseplaneTypes[0]);
// }
finishTransformed(cmd, FeatName);
};
@ -1456,10 +1441,11 @@ void CmdPartDesignLinearPattern::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaselineTypes[0]);
}
// TODO Check if default direction correctly set (2015-09-01, Fat-Zer)
// else {
// doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
// App::Part::BaselineTypes[0]);
// }
doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());
@ -1505,10 +1491,11 @@ void CmdPartDesignPolarPattern::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaselineTypes[0]);
}
// TODO Check if default axis correctly set (2015-09-01, Fat-Zer)
// else {
// doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
// App::Part::BaselineTypes[0]);
// }
doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());

View File

@ -101,8 +101,8 @@ void CmdPartDesignPart::activated(int iMsg)
// TODO We really must to set label ourselfs? (2015-08-17, Fat-Zer)
doCommand(Doc,"App.activeDocument().%s.Label = '%s'", PartName.c_str(),
QObject::tr(PartName.c_str()).toUtf8().data());
PartDesignGui::setUpPart(dynamic_cast<App::Part *>(getDocument()->getObject(PartName.c_str())));
doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str());
doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)",
PARTKEY, PartName.c_str());
updateActive();
}

View File

@ -209,17 +209,19 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
ui->listOfModes->blockSignals(false);
updateUI();
updateListOfModes(eMapMode(pcDatum->MapMode.getValue()));
//temporary show coordinate systems for selection
App::Part* part = getPartFor(DatumView->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, true);
}
}
if(part) {
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, true);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
if (pcDatum->Support.getSize() == 0)
autoNext = true;
else
@ -771,14 +773,16 @@ TaskDatumParameters::~TaskDatumParameters()
//end temporary view mode of coordinate system
App::Part* part = getPartFor(DatumView->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;
}

View File

@ -89,7 +89,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
enum { axisBit=0, planeBit = 1};
// Note generally there shouldn't be more then one origin
// NOTE: generally there shouldn't be more then one origin
std::map <App::Origin*, std::bitset<2> > originVisStatus;
auto statusIt = status.cbegin();
@ -110,18 +110,24 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
} else if ( (*objIt)->isDerivedFrom ( App::Line::getClassTypeId () ) ) {
originVisStatus[ origin ].set (axisBit, true);
}
Gui::ViewProviderOrigin* vpo = static_cast<Gui::ViewProviderOrigin*> (
Gui::Application::Instance->getViewProvider(*objIt) );
if (vpo) {
vpo->setTemporaryVisibility( originVisStatus[origin][axisBit],
originVisStatus[origin][planeBit]);
}
origins.push_back(vpo);
}
}
}
// Setup the origin's temporary visability
for ( const auto & originPair: originVisStatus ) {
const auto &origin = originPair.first;
const auto &status = originPair.second;
Gui::ViewProviderOrigin* vpo = static_cast<Gui::ViewProviderOrigin*> (
Gui::Application::Instance->getViewProvider ( origin ) );
if (vpo) {
vpo->setTemporaryVisibility( originVisStatus[origin][axisBit],
originVisStatus[origin][planeBit]);
origins.push_back(vpo);
}
}
// TODO may be update origin API to show only some objects (2015-08-31, Fat-Zer)
groupLayout()->addWidget(proxy);

View File

@ -166,12 +166,14 @@ void TaskLinearPatternParameters::setupUI()
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, false);
if(part) {
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@ -223,29 +225,20 @@ void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
} else {
// TODO check if this works correctly (2015-09-01, Fat-Zer)
exitSelectionMode();
std::vector<std::string> directions;
App::DocumentObject* selObj;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
getReferencedSelection(pcLinearPattern, msg, selObj, directions);
pcLinearPattern->Direction.setValue(selObj, directions);
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) {
pcLinearPattern->Direction.setValue(selObj, directions);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) {
std::vector<std::string> directions;
App::DocumentObject* selObj;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
getReferencedSelection(pcLinearPattern, msg, selObj, directions);
pcLinearPattern->Direction.setValue(selObj, directions);
recomputeFeature();
updateUI();
recomputeFeature();
updateUI();
}
}
}
}
@ -366,12 +359,14 @@ TaskLinearPatternParameters::~TaskLinearPatternParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;

View File

@ -132,22 +132,23 @@ void TaskMirroredParameters::setupUI()
this->planeLinks.setCombo(*(ui->comboPlane));
ui->comboPlane->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (!sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
sketch = 0;
this->fillPlanesCombo(planeLinks,static_cast<Part::Part2DObject*>(sketch));
updateUI();
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin.front() ));
origin->setTemporaryVisibility(true, false);
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@ -179,30 +180,20 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
} else {
// TODO checkme (2015-09-01, Fat-Zer)
exitSelectionMode();
std::vector<std::string> mirrorPlanes;
App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference || selObj->isDerivedFrom ( App::Plane::getClassTypeId () ) ) {
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaseplaneTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[2]) == nullptr) {
std::vector<std::string> planes;
App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, planes);
pcMirrored->MirrorPlane.setValue(selObj, planes);
recomputeFeature();
updateUI();
recomputeFeature();
updateUI();
}
}
}
}
@ -278,15 +269,16 @@ TaskMirroredParameters::~TaskMirroredParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;
if (proxy)
delete proxy;

View File

@ -161,12 +161,14 @@ void TaskPolarPatternParameters::setupUI()
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, false);
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@ -217,29 +219,20 @@ void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges&
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
} else {
// TODO checkme (2015-09-01, Fat-Zer)
exitSelectionMode();
std::vector<std::string> axes;
App::DocumentObject* selObj;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
getReferencedSelection(pcPolarPattern, msg, selObj, axes);
pcPolarPattern->Axis.setValue(selObj, axes);
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) {
pcPolarPattern->Axis.setValue(selObj, axes);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) {
std::vector<std::string> axes;
App::DocumentObject* selObj;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
getReferencedSelection(pcPolarPattern, msg, selObj, axes);
pcPolarPattern->Axis.setValue(selObj, axes);
recomputeFeature();
updateUI();
recomputeFeature();
updateUI();
}
}
}
}
@ -361,12 +354,14 @@ TaskPolarPatternParameters::~TaskPolarPatternParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility ();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;

View File

@ -133,12 +133,14 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider*
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(vp->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, false);
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@ -179,9 +181,7 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill)
if (part) {
try {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
App::Origin* orig = part->getOrigin();
addAxisToCombo(orig->getX(),"",tr("Base X axis"));
addAxisToCombo(orig->getY(),"",tr("Base Y axis"));
addAxisToCombo(orig->getZ(),"",tr("Base Z axis"));
@ -362,14 +362,16 @@ TaskRevolutionParameters::~TaskRevolutionParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(vp->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;
for(int i = 0 ; i < axesInList.size() ; i++ ){

View File

@ -196,9 +196,7 @@ void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks,
if (part) {
try {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
App::Origin* orig = part->getOrigin();
combolinks.addLink(orig->getX(),"",tr("Base X axis"));
combolinks.addLink(orig->getY(),"",tr("Base Y axis"));
combolinks.addLink(orig->getZ(),"",tr("Base Z axis"));
@ -234,9 +232,7 @@ void TaskTransformedParameters::fillPlanesCombo(ComboLinks &combolinks,
if (part) {
try {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
App::Origin* orig = part->getOrigin();
combolinks.addLink(orig->getXY(),"",tr("Base XY plane"));
combolinks.addLink(orig->getYZ(),"",tr("Base YZ plane"));
combolinks.addLink(orig->getXZ(),"",tr("Base XZ plane"));

View File

@ -29,6 +29,8 @@
#endif
#include <App/Part.h>
#include <App/Origin.h>
#include <App/OriginFeature.h>
#include <App/DocumentObjectGroup.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
@ -132,27 +134,6 @@ static void buildDefaultPartAndBody(const App::Document* doc)
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str());
}
PartDesign::Body *setUpPart(const App::Part *part)
{
// first do the general Part setup
Gui::ViewProviderPart::setUpPart(part);
// check for Bodies
// std::vector<App::DocumentObject*> bodies = part->getObjectsOfType(PartDesign::Body::getClassTypeId());
// assert(bodies.size() == 0);
// std::string PartName = part->getNameInDocument();
// std::string BodyName = part->getDocument()->getUniqueObjectName("MainBody");
Gui::Command::addModule(Gui::Command::Doc, "PartDesign");
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().addObject('PartDesign::Body','%s')", BodyName.c_str());
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
// Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, BodyName.c_str());
Gui::Command::updateActive();
return NULL;
}
void fixSketchSupport (Sketcher::SketchObject* sketch)
{
@ -163,11 +144,17 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
const App::Document* doc = sketch->getDocument();
PartDesign::Body *body = getBodyFor(sketch, /*messageIfNot*/ 0);
if (!body) {
throw Base::Exception ("Coudn't find body for the sketch");
}
// Get the Origin for the body
App::OriginGroup *grp = App::OriginGroup::getGroupOfObject (body);
if (!grp) {
throw Base::Exception ("Coudn't find group for body");
}
App::Origin *origin = grp->getOrigin (); // May throw by itself
Base::Placement plm = sketch->Placement.getValue();
Base::Vector3d pnt = plm.getPosition();
@ -177,17 +164,19 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
rot.multVec(sketchVector, sketchVector);
bool reverseSketch = (sketchVector.x + sketchVector.y + sketchVector.z) < 0.0 ;
if (reverseSketch) sketchVector *= -1.0;
int index;
App::Plane *plane =0;
if (sketchVector == Base::Vector3d(0,0,1))
index = 0;
plane = origin->getXY ();
else if (sketchVector == Base::Vector3d(0,1,0))
index = 1;
plane = origin->getXZ ();
else if (sketchVector == Base::Vector3d(1,0,0))
index = 2;
plane = origin->getYZ ();
else {
throw Base::Exception("Sketch plane cannot be migrated");
}
assert (plane);
// Find the normal distance from origin to the sketch plane
gp_Pln pln(gp_Pnt (pnt.x, pnt.y, pnt.z), gp_Dir(sketchVector.x, sketchVector.y, sketchVector.z));
@ -197,7 +186,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
if (fabs(offset) < Precision::Confusion()) {
// One of the base planes
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])",
sketch->getNameInDocument(), App::Part::BaseplaneTypes[index]);
sketch->getNameInDocument(), plane->getNameInDocument () );
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s",
sketch->getNameInDocument(), reverseSketch ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
@ -211,16 +200,21 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
offset *= -1.0;
std::string Datum = doc->getUniqueObjectName("DatumPlane");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('PartDesign::Plane','%s')",Datum.c_str());
QString refStr = QString::fromAscii("[(App.activeDocument().") + QString::fromAscii(App::Part::BaseplaneTypes[index]) +
QString::fromAscii(",'')]");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",Datum.c_str(), refStr.toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f",Datum.c_str(), offset);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('PartDesign::Plane','%s')",
Datum.c_str());
QString refStr = QString::fromAscii("[(App.activeDocument().%1,'')]")
.arg ( QString::fromAscii ( plane->getNameInDocument () ) );
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",
Datum.c_str(), refStr.toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f",
Datum.c_str(), offset);
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.insertFeature(App.activeDocument().%s, App.activeDocument().%s)",
body->getNameInDocument(), Datum.c_str(), sketch->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])",
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])",
sketch->getNameInDocument(), Datum.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s",
sketch->getNameInDocument(), reverseSketch ? "True" : "False");

View File

@ -51,17 +51,6 @@ PartDesign::Body *getBody(bool messageIfNot);
PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot);
App::Part *getPartFor(const App::DocumentObject*, bool messageIfNot);
/** Setup a Part for PartDesign
* This methode is use to populate a Part object with all
* necesarry PartDesign and base objects to allow the use
* in PartDesign. Its called from within PartDesign as well
* as from other modules which wish to set up a Part for PartDesin
* (e.g. Assembly):
* TODO any reasons why this should return a value? (2015-08-08, Fat-Zer)
*/
PartDesign::Body *setUpPart(const App::Part *);
/// Fix sketch support after moving a free sketch into a body
void fixSketchSupport(Sketcher::SketchObject* sketch);