/*************************************************************************** * Copyright (c) 2011 Juergen Riegel * * * * 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 #endif #include "ViewProviderBody.h" #include "Workbench.h" #include #include #include #include #include #include #include #include #include #include "Base/Console.h" using namespace PartDesignGui; PROPERTY_SOURCE(PartDesignGui::ViewProviderBody,PartGui::ViewProviderPart) ViewProviderBody::ViewProviderBody() { pcBodyChildren = new SoGroup(); pcBodyChildren->ref(); pcBodyTip = new SoGroup(); pcBodyTip->ref(); sPixmap = "PartDesign_Body_Tree.svg"; } ViewProviderBody::~ViewProviderBody() { pcBodyChildren->unref(); pcBodyChildren = 0; pcBodyTip->unref(); pcBodyTip = 0; } void ViewProviderBody::attach(App::DocumentObject *pcFeat) { // call parent attach method ViewProviderPart::attach(pcFeat); // putting all together with the switch addDisplayMaskMode(pcBodyTip, "Body"); addDisplayMaskMode(pcBodyChildren, "Through"); } void ViewProviderBody::setDisplayMode(const char* ModeName) { if ( strcmp("Body",ModeName)==0 ) setDisplayMaskMode("Body"); if ( strcmp("Main",ModeName)==0 ) setDisplayMaskMode("Main"); if ( strcmp("Through",ModeName)==0 ) setDisplayMaskMode("Through"); ViewProviderGeometryObject::setDisplayMode( ModeName ); } std::vector ViewProviderBody::getDisplayModes(void) const { // get the modes of the father std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); // add your own modes StrList.push_back("Through"); StrList.push_back("Body"); return StrList; } bool ViewProviderBody::doubleClicked(void) { // assure the PartDesign workbench Gui::Command::assureWorkbench("PartDesignWorkbench"); //Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",this->getObject()->getNameInDocument()); Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, this->getObject()->getNameInDocument()); return true; } std::vector ViewProviderBody::claimChildren(void)const { std::vector Model = static_cast(getObject())->Model.getValues(); std::set OutSet; // search for objects handled (claimed) by the features for(std::vector::const_iterator it = Model.begin();it!=Model.end();++it){ if (*it == NULL) continue; Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(*it); if (vp == NULL) continue; std::vector children = vp->claimChildren(); for (std::vector::const_iterator ch = children.begin(); ch != children.end(); ch++) { if ((*ch) != NULL) OutSet.insert(*ch); } } // remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct std::vector Result; for (std::vector::const_iterator it = Model.begin();it!=Model.end();++it) { if (OutSet.find(*it) == OutSet.end()) Result.push_back(*it); } // return the rest as claim set of the Body return Result; } std::vector ViewProviderBody::claimChildren3D(void)const { //std::vector children = static_cast(getObject())->Model.getValues(); //Base::Console().Error("Body 3D claimed children:\n"); //for (std::vector::const_iterator o = children.begin(); o != children.end(); o++) // Base::Console().Error("%s\n", (*o)->getNameInDocument()); return static_cast(getObject())->Model.getValues(); } //void ViewProviderBody::updateTree() //{ // if (ActiveGuiDoc == NULL) return; // // // Highlight active body and all its features // //Base::Console().Error("ViewProviderBody::updateTree()\n"); // PartDesign::Body* body = static_cast(getObject()); // bool active = body->IsActive.getValue(); // //Base::Console().Error("Body is %s\n", active ? "active" : "inactive"); // ActiveGuiDoc->signalHighlightObject(*this, Gui::Blue, active); // std::vector features = body->Model.getValues(); // bool highlight = true; // App::DocumentObject* tip = body->Tip.getValue(); // for (std::vector::const_iterator f = features.begin(); f != features.end(); f++) { // //Base::Console().Error("Highlighting %s: %s\n", (*f)->getNameInDocument(), highlight ? "true" : "false"); // Gui::ViewProviderDocumentObject* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*f)); // if (vp != NULL) // ActiveGuiDoc->signalHighlightObject(*vp, Gui::LightBlue, active ? highlight : false); // if (highlight && (tip == *f)) // highlight = false; // } //} void ViewProviderBody::updateData(const App::Property* prop) { //Base::Console().Error("ViewProviderBody::updateData for %s\n", getObject()->getNameInDocument()); //if (ActiveGuiDoc == NULL) // // PartDesign workbench not active // return PartGui::ViewProviderPart::updateData(prop); //if ((/*prop->getTypeId() == App::PropertyBool::getClassTypeId() && strcmp(prop->getName(),"IsActive") == 0) ||*/ // (prop->getTypeId() == App::PropertyLink::getClassTypeId() && strcmp(prop->getName(),"Tip") == 0) || // (prop->getTypeId() == App::PropertyLinkList::getClassTypeId() && strcmp(prop->getName(),"Model") == 0)) // // updateTree(); // Update the visual size of datum lines and planes PartDesign::Body* body = static_cast(getObject()); std::vector features = body->Model.getValues(); for (std::vector::const_iterator f = features.begin(); f != features.end(); f++) { App::PropertyPlacement* plm = NULL; if ((*f)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) plm = &(static_cast(*f)->Placement); else if ((*f)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) plm = &(static_cast(*f)->Placement); if (plm != NULL) { Gui::ViewProviderDocumentObject* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*f)); if (vp != NULL) vp->updateData(plm); } } PartGui::ViewProviderPart::updateData(prop); }