Adding ViewProvider

This commit is contained in:
jriegel
2012-01-15 21:44:52 +01:00
committed by Stefan Tröger
parent 075bd74d9b
commit cb499ac2c7
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;
}