1
/***************************************************************************
2
* Copyright (c) 2004 J�rgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
28
# include <Inventor/nodes/SoDrawStyle.h>
29
# include <Inventor/nodes/SoMaterial.h>
30
# include <Inventor/nodes/SoSeparator.h>
33
/// Here the FreeCAD includes sorted by Base,App,Gui......
34
#include <Base/Console.h>
35
#include <App/Material.h>
36
#include <App/Feature.h>
37
#include "Application.h"
39
#include "Selection.h"
40
#include "ViewProviderDocumentObject.h"
41
#include "ViewProviderDocumentObjectPy.h"
47
PROPERTY_SOURCE(Gui::ViewProviderDocumentObject, Gui::ViewProvider)
49
ViewProviderDocumentObject::ViewProviderDocumentObject()
52
ADD_PROPERTY(DisplayMode,((long)0));
53
ADD_PROPERTY(Visibility,(true));
59
ViewProviderDocumentObject::~ViewProviderDocumentObject()
61
// Make sure that the property class does not destruct our string list
62
DisplayMode.setEnums(0);
65
void ViewProviderDocumentObject::onChanged(const App::Property* prop)
67
if (prop == &DisplayMode) {
70
else if (prop == &Visibility) {
71
Visibility.getValue() ? ViewProvider::show() : ViewProvider::hide();
75
void ViewProviderDocumentObject::hide(void)
77
Visibility.setValue(false);
80
void ViewProviderDocumentObject::show(void)
82
Visibility.setValue(true);
85
void ViewProviderDocumentObject::updateView()
87
std::map<std::string, App::Property*> Map;
88
pcObject->getPropertyMap(Map);
90
// Hide the object temporarily to speed up the update
91
bool vis = this->isShow();
93
for (std::map<std::string, App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
94
updateData(it->second);
99
void ViewProviderDocumentObject::attach(App::DocumentObject *pcObj)
101
// save Object pointer
104
// Retrieve the supported display modes of the view provider
105
aDisplayModesArray = this->getDisplayModes();
107
if( aDisplayModesArray.empty() )
108
aDisplayModesArray.push_back("");
110
// We must collect the const char* of the strings and give it to PropertyEnumeration,
111
// but we are still responsible for them, i.e. the property class must not delete the literals.
112
for ( std::vector<std::string>::iterator it = aDisplayModesArray.begin(); it != aDisplayModesArray.end(); ++it ) {
113
aDisplayEnumsArray.push_back( it->c_str() );
115
aDisplayEnumsArray.push_back(0); // null termination
116
DisplayMode.setEnums(&(aDisplayEnumsArray[0]));
118
// set the active mode
119
const char* defmode = this->getDefaultDisplayMode();
121
DisplayMode.setValue(defmode);
124
SoSeparator* ViewProviderDocumentObject::findFrontRootOfType( const SoType& type) const
126
// first get the document this object is part of and get its GUI counterpart
127
App::Document* pAppDoc = pcObject->getDocument();
128
Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(pAppDoc);
130
// search in all view providers for the node type
131
std::vector<App::DocumentObject*> obj = pAppDoc->getObjects();
132
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
133
const ViewProvider* vp = pGuiDoc->getViewProvider(*it);
134
// Ignore 'this' view provider. It could also happen that vp is 0, e.g. when
135
// several objects have been added to the App::Document before notifying the
137
if (!vp || vp == this)
139
SoSeparator* front = vp->getFrontRoot();
140
if (front && front->getTypeId() == type)
147
void ViewProviderDocumentObject::setActiveMode()
149
if (DisplayMode.getEnums()) {
150
const char* mode = DisplayMode.getValueAsString();
152
setDisplayMode(mode);
154
if (!Visibility.getValue())
155
ViewProvider::hide();
158
const char* ViewProviderDocumentObject::getDefaultDisplayMode() const
160
// We use the first item then
164
std::vector<std::string> ViewProviderDocumentObject::getDisplayModes(void) const
167
return std::vector<std::string>();
170
PyObject* ViewProviderDocumentObject::getPyObject()
173
pyViewObject = new ViewProviderDocumentObjectPy(this);
174
pyViewObject->IncRef();