Adding ViewProvider

This commit is contained in:
jriegel 2012-01-15 21:44:52 +01:00 committed by Stefan Tröger
parent 04feea80b1
commit 1feafdd2c5
9 changed files with 174 additions and 11 deletions

View File

@ -40,6 +40,7 @@ PROPERTY_SOURCE(Assembly::Item, Part::Feature)
Item::Item()
{
ADD_PROPERTY(Id,(0));
ADD_PROPERTY(Uid,(0));
ADD_PROPERTY(Name,(0));
ADD_PROPERTY(Description,(0));
}

View File

@ -38,9 +38,17 @@ class AssemblyExport Item : public Part::Feature
public:
Item();
/** @name base properties of all Assembly Items */
//@{
/// Id e.g. Part number
App::PropertyString Id;
/// unique identifier of the Item
App::PropertyUUID Uid;
/// Name of the Item (human readable)
App::PropertyString Name ;
/// long description of the Item
App::PropertyString Description ;
//@}
/** @name methods override feature */
//@{
@ -48,9 +56,9 @@ public:
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
/// returns the type name of the view provider
//const char* getViewProviderName(void) const {
// return "PartDesignGui::ViewProviderItem";
//}
const char* getViewProviderName(void) const {
return "PartDesignGui::ViewProviderItem";
}
//@}
};

View File

@ -23,9 +23,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Builder.hxx>
#endif
#include <Base/Placement.h>
#include <Base/Exception.h>
#include "ItemAssembly.h"
@ -52,8 +54,34 @@ short ItemAssembly::mustExecute() const
App::DocumentObjectExecReturn *ItemAssembly::execute(void)
{
std::vector<TopoDS_Shape> s;
std::vector<App::DocumentObject*> obj = Items.getValues();
std::vector<App::DocumentObject*>::iterator it;
for (it = obj.begin(); it != obj.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
s.push_back(static_cast<Assembly::Item*>(*it)->Shape.getValue());
}
}
if (s.size() > 0) {
TopoDS_Compound aRes = TopoDS_Compound();
BRep_Builder aBuilder = BRep_Builder();
aBuilder.MakeCompound(aRes);
for (std::vector<TopoDS_Shape>::iterator it = s.begin(); it != s.end(); ++it) {
aBuilder.Add(aRes, *it);
}
if (aRes.IsNull())
throw Base::Exception("Resulting shape is invalid");
this->Shape.setValue(aRes);
}
else {
// set empty shape
this->Shape.setValue(TopoDS_Shape());
}
return App::DocumentObject::StdReturn;
}
}
}

View File

@ -46,9 +46,9 @@ public:
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
/// returns the type name of the view provider
//const char* getViewProviderName(void) const {
// return "PartDesignGui::ViewProviderItemAssembly";
//}
const char* getViewProviderName(void) const {
return "PartDesignGui::ViewProviderItemAssembly";
}
//@}
};

View File

@ -52,7 +52,12 @@ short ItemPart::mustExecute() const
App::DocumentObjectExecReturn *ItemPart::execute(void)
{
App::DocumentObject* obj = Model.getValue();
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
this->Shape.setValue(static_cast<Part::Feature*>(obj)->Shape.getValue());
}
return App::DocumentObject::StdReturn;
}

View File

@ -10,8 +10,10 @@ include_directories(
${Boost_INCLUDE_DIRS}
${COIN_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${OCC_INCLUDE_DIR}
${QT_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
${COIN3D_INCLUDE_DIRS}
${XercesC_INCLUDE_DIRS}
#${ODE_INCLUDE_DIRS}
)
@ -19,22 +21,38 @@ include_directories(
set(AssemblyGui_LIBS
#${ODE_LIBRARIES}
Assembly
PartGui
FreeCADGui
)
qt4_add_resources(AssemblyGui_SRCS Resources/Assembly.qrc)
SET(AssemblyGui_SRCS
${AssemblyGui_SRCS}
SET(AssemblyGuiViewProvider_SRCS
ViewProvider.cpp
ViewProvider.h
)
SOURCE_GROUP("ViewProvider" FILES ${AssemblyGuiViewProvider_SRCS})
SET(AssemblyGuiModule_SRCS
AppAssemblyGui.cpp
AppAssemblyGuiPy.cpp
Command.cpp
Resources/Assembly.qrc
qrc_Assembly.cxx
PreCompiled.cpp
PreCompiled.h
Workbench.cpp
Workbench.h
)
SOURCE_GROUP("Module" FILES ${AssemblyGuiModule_SRCS})
SET(AssemblyGui_SRCS
${AssemblyGui_SRCS}
${AssemblyGuiViewProvider_SRCS}
${AssemblyGuiModule_SRCS}
)
add_library(AssemblyGui SHARED ${AssemblyGui_SRCS})
target_link_libraries(AssemblyGui ${AssemblyGui_LIBS})

View File

@ -29,9 +29,11 @@
// Importing of App classes
#ifdef FC_OS_WIN32
# define AssemblyAppExport __declspec(dllimport)
# define PartGuiExport __declspec(dllimport)
# define AssemblyGuiExport __declspec(dllexport)
#else // for Linux
# define AssemblyAppExport
# define PartGuiExport
# define AssemblyGuiExport
#endif

View File

@ -0,0 +1,50 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 "ViewProvider.h"
#include <Gui/Command.h>
//#include <Gui/Document.h>
using namespace AssemblyGui;
PROPERTY_SOURCE(AssemblyGui::ViewProvider,PartGui::ViewProviderPart)
ViewProvider::ViewProvider()
{
}
ViewProvider::~ViewProvider()
{
}
bool ViewProvider::doubleClicked(void)
{
return true;
}

View File

@ -0,0 +1,51 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 PARTGUI_ViewProvider_H
#define PARTGUI_ViewProvider_H
#include <Mod/Part/Gui/ViewProvider.h>
namespace AssemblyGui {
class AssemblyGuiExport ViewProvider : public PartGui::ViewProviderPart
{
PROPERTY_HEADER(PartGui::ViewProvider);
public:
/// constructor
ViewProvider();
/// destructor
virtual ~ViewProvider();
virtual bool doubleClicked(void);
};
} // namespace AssemblyGui
#endif // PARTGUI_ViewProviderHole_H