Simplify logic using freecad_dynamic_cast
This commit is contained in:
@@ -143,12 +143,8 @@ void DemoMode::hideEvent(QHideEvent*)
|
||||
|
||||
Gui::View3DInventor* DemoMode::activeView() const
|
||||
{
|
||||
Document* doc = Application::Instance->activeDocument();
|
||||
if (doc) {
|
||||
MDIView* view = doc->getActiveView();
|
||||
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
|
||||
return static_cast<Gui::View3DInventor*>(view);
|
||||
}
|
||||
if (Document* doc = Application::Instance->activeDocument()) {
|
||||
return Base::freecad_dynamic_cast<Gui::View3DInventor>(doc->getActiveView());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
@@ -186,14 +186,14 @@ App::DocumentObjectExecReturn* FeatureViewSpreadsheet::execute(void)
|
||||
App::Property* prop = sheet->getPropertyByName(address.toString().c_str());
|
||||
std::stringstream field;
|
||||
if (prop) {
|
||||
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) {
|
||||
field << static_cast<App::PropertyQuantity*>(prop)->getValue();
|
||||
if (auto* p = Base::freecad_dynamic_cast<App::PropertyQuantity>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId()))) {
|
||||
field << static_cast<App::PropertyFloat*>(prop)->getValue();
|
||||
else if (auto p = Base::freecad_dynamic_cast<App::PropertyFloat>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId()))) {
|
||||
field << static_cast<App::PropertyString*>(prop)->getValue();
|
||||
else if (auto p = Base::freecad_dynamic_cast<App::PropertyString>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
|
||||
@@ -468,12 +468,9 @@ void FemPostClipFilter::onChanged(const Property* prop)
|
||||
{
|
||||
if (prop == &Function) {
|
||||
|
||||
if (Function.getValue()
|
||||
&& Function.getValue()->isDerivedFrom(FemPostFunction::getClassTypeId())) {
|
||||
m_clipper->SetClipFunction(
|
||||
static_cast<FemPostFunction*>(Function.getValue())->getImplicitFunction());
|
||||
m_extractor->SetImplicitFunction(
|
||||
static_cast<FemPostFunction*>(Function.getValue())->getImplicitFunction());
|
||||
if (auto* value = Base::freecad_dynamic_cast<FemPostFunction>(Function.getValue())) {
|
||||
m_clipper->SetClipFunction(value->getImplicitFunction());
|
||||
m_extractor->SetImplicitFunction(value->getImplicitFunction());
|
||||
}
|
||||
}
|
||||
else if (prop == &InsideOut) {
|
||||
@@ -922,10 +919,8 @@ FemPostCutFilter::~FemPostCutFilter() = default;
|
||||
void FemPostCutFilter::onChanged(const Property* prop)
|
||||
{
|
||||
if (prop == &Function) {
|
||||
if (Function.getValue()
|
||||
&& Function.getValue()->isDerivedFrom(FemPostFunction::getClassTypeId())) {
|
||||
m_cutter->SetCutFunction(
|
||||
static_cast<FemPostFunction*>(Function.getValue())->getImplicitFunction());
|
||||
if (auto* value = Base::freecad_dynamic_cast<FemPostFunction>(Function.getValue())) {
|
||||
m_cutter->SetCutFunction(value->getImplicitFunction());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -329,17 +329,19 @@ bool Sheet::exportToFile(const std::string& filename,
|
||||
|
||||
std::stringstream field;
|
||||
|
||||
if (prop->isDerivedFrom((PropertyQuantity::getClassTypeId()))) {
|
||||
field << static_cast<PropertyQuantity*>(prop)->getValue();
|
||||
using Base::freecad_dynamic_cast;
|
||||
|
||||
if (auto p = freecad_dynamic_cast<PropertyQuantity>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else if (prop->isDerivedFrom((PropertyFloat::getClassTypeId()))) {
|
||||
field << static_cast<PropertyFloat*>(prop)->getValue();
|
||||
else if (auto p = freecad_dynamic_cast<PropertyFloat>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else if (prop->isDerivedFrom((PropertyInteger::getClassTypeId()))) {
|
||||
field << static_cast<PropertyInteger*>(prop)->getValue();
|
||||
else if (auto p = freecad_dynamic_cast<PropertyInteger>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else if (prop->isDerivedFrom((PropertyString::getClassTypeId()))) {
|
||||
field << static_cast<PropertyString*>(prop)->getValue();
|
||||
else if (auto p = freecad_dynamic_cast<PropertyString>(prop)) {
|
||||
field << p->getValue();
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
|
||||
@@ -390,57 +390,57 @@ bool QGSPage::addView(const App::DocumentObject* obj)
|
||||
bool QGSPage::attachView(App::DocumentObject* obj)
|
||||
{
|
||||
// Base::Console().Message("QGSP::attachView(%s)\n", obj->getNameInDocument());
|
||||
QGIView* existing = findQViewForDocObj(obj);
|
||||
if (existing)
|
||||
if (findQViewForDocObj(obj)) {
|
||||
return true;
|
||||
|
||||
auto typeId(obj->getTypeId());
|
||||
}
|
||||
|
||||
QGIView* qview(nullptr);
|
||||
|
||||
if (typeId.isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) {
|
||||
qview = addViewSection(static_cast<TechDraw::DrawViewSection*>(obj));
|
||||
using Base::freecad_dynamic_cast;
|
||||
|
||||
if (auto o = freecad_dynamic_cast<TechDraw::DrawViewSection>(obj)) {
|
||||
qview = addViewSection(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
|
||||
qview = addViewPart(static_cast<TechDraw::DrawViewPart*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewPart>(obj)) {
|
||||
qview = addViewPart(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) {
|
||||
qview = addProjectionGroup(static_cast<TechDraw::DrawProjGroup*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawProjGroup>(obj)) {
|
||||
qview = addProjectionGroup(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId())) {
|
||||
qview = addDrawView(static_cast<TechDraw::DrawViewCollection*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewCollection>(obj)) {
|
||||
qview = addDrawView(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
|
||||
qview = addViewDimension(static_cast<TechDraw::DrawViewDimension*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewDimension>(obj)) {
|
||||
qview = addViewDimension(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) {
|
||||
qview = addViewBalloon(static_cast<TechDraw::DrawViewBalloon*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewBalloon>(obj)) {
|
||||
qview = addViewBalloon(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) {
|
||||
qview = addAnnotation(static_cast<TechDraw::DrawViewAnnotation*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewAnnotation>(obj)) {
|
||||
qview = addAnnotation(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId())) {
|
||||
qview = addDrawViewSymbol(static_cast<TechDraw::DrawViewSymbol*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewSymbol>(obj)) {
|
||||
qview = addDrawViewSymbol(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) {
|
||||
qview = addDrawViewClip(static_cast<TechDraw::DrawViewClip*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewClip>(obj)) {
|
||||
qview = addDrawViewClip(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId())) {
|
||||
qview = addDrawViewSpreadsheet(static_cast<TechDraw::DrawViewSpreadsheet*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewSpreadsheet>(obj)) {
|
||||
qview = addDrawViewSpreadsheet(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawViewImage::getClassTypeId())) {
|
||||
qview = addDrawViewImage(static_cast<TechDraw::DrawViewImage*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawViewImage>(obj)) {
|
||||
qview = addDrawViewImage(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) {
|
||||
qview = addViewLeader(static_cast<TechDraw::DrawLeaderLine*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawLeaderLine>(obj)) {
|
||||
qview = addViewLeader(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) {
|
||||
qview = addRichAnno(static_cast<TechDraw::DrawRichAnno*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawRichAnno>(obj)) {
|
||||
qview = addRichAnno(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())) {
|
||||
qview = addWeldSymbol(static_cast<TechDraw::DrawWeldSymbol*>(obj));
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawWeldSymbol>(obj)) {
|
||||
qview = addWeldSymbol(o);
|
||||
}
|
||||
else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId())) {
|
||||
else if (auto o = freecad_dynamic_cast<TechDraw::DrawHatch>(obj)) {
|
||||
//Hatch is not attached like other Views (since it isn't really a View)
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user