FreeCAD

Форк
0
/
ViewProviderGeoFeatureGroupExtension.cpp 
159 строк · 6.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Jürgen Riegel <FreeCAD@juergen-riegel.net>         *
3
 *   Copyright (c) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com>    *
4
 *   Copyright (c) 2016 Stefan Tröger <stefantroeger@gmx.net>              *
5
 *                                                                         *
6
 *   This file is part of the FreeCAD CAx development system.              *
7
 *                                                                         *
8
 *   This library is free software; you can redistribute it and/or         *
9
 *   modify it under the terms of the GNU Library General Public           *
10
 *   License as published by the Free Software Foundation; either          *
11
 *   version 2 of the License, or (at your option) any later version.      *
12
 *                                                                         *
13
 *   This library  is distributed in the hope that it will be useful,      *
14
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16
 *   GNU Library General Public License for more details.                  *
17
 *                                                                         *
18
 *   You should have received a copy of the GNU Library General Public     *
19
 *   License along with this library; see the file COPYING.LIB. If not,    *
20
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
21
 *   Suite 330, Boston, MA  02111-1307, USA                                *
22
 *                                                                         *
23
 ***************************************************************************/
24

25
#include "PreCompiled.h"
26

27
#ifndef _PreComp_
28
#include <Inventor/nodes/SoSeparator.h>
29
#endif
30

31
#include <App/DocumentObject.h>
32
#include <App/GeoFeatureGroupExtension.h>
33

34
#include "ViewProviderGeoFeatureGroupExtension.h"
35
#include "ViewProviderDocumentObject.h"
36
#include "Application.h"
37
#include "SoFCUnifiedSelection.h"
38

39

40
using namespace Gui;
41

42
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderGeoFeatureGroupExtension, Gui::ViewProviderGroupExtension)
43

44
ViewProviderGeoFeatureGroupExtension::ViewProviderGeoFeatureGroupExtension()
45
{
46
    initExtensionType(ViewProviderGeoFeatureGroupExtension::getExtensionClassTypeId());
47

48
    pcGroupChildren = new SoFCSelectionRoot;
49
    pcGroupChildren->ref();
50
    pcGroupFront = new SoSeparator();
51
    pcGroupFront->ref();
52
    pcGroupBack = new SoSeparator();
53
    pcGroupBack->ref();
54
}
55

56
ViewProviderGeoFeatureGroupExtension::~ViewProviderGeoFeatureGroupExtension()
57
{
58
    pcGroupChildren->unref();
59
    pcGroupChildren = nullptr;
60
    pcGroupFront->unref();
61
    pcGroupFront = nullptr;
62
    pcGroupBack->unref();
63
    pcGroupBack = nullptr;
64
}
65

66

67
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D() const {
68

69
    //all object in the group must be claimed in 3D, as we are a coordinate system for all of them
70
    auto* ext = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
71
    if (ext) {
72
        auto objs = ext->Group.getValues();
73
        return objs;
74
    }
75
    return {};
76
}
77

78
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren() const {
79

80
    auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
81
    const std::vector<App::DocumentObject*> &model = group->Group.getValues ();
82
    std::set<App::DocumentObject*> outSet; //< set of objects not to claim (childrens of childrens)
83

84
    // search for objects handled (claimed) by the features
85
    for (auto obj: model) {
86
        //stuff in another geofeaturegroup is not in the model anyway
87
        if (!obj || obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) { continue; }
88

89
        Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj );
90
        if (!vp || vp == getExtendedViewProvider()) { continue; }
91

92
        auto children = vp->claimChildren();
93
        std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr);
94
    }
95

96
    // remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct
97
    std::vector<App::DocumentObject*> Result;
98
    for(auto obj : model) {
99
        if(!obj || !obj->isAttachedToDocument())
100
            continue;
101
        if(outSet.count(obj))
102
            obj->setStatus(App::ObjectStatus::GeoExcluded,true);
103
        else {
104
            obj->setStatus(App::ObjectStatus::GeoExcluded,false);
105
            Result.push_back(obj);
106
        }
107
    }
108
    return Result;
109
}
110

111
void ViewProviderGeoFeatureGroupExtension::extensionFinishRestoring()
112
{
113
    // setup GeoExlcuded flag for children
114
    extensionClaimChildren();
115
    ViewProviderGroupExtension::extensionFinishRestoring();
116
}
117

118
void ViewProviderGeoFeatureGroupExtension::extensionAttach(App::DocumentObject* pcObject)
119
{
120
    ViewProviderGroupExtension::extensionAttach(pcObject);
121
    getExtendedViewProvider()->addDisplayMaskMode(pcGroupChildren, "Group");
122
}
123

124
void ViewProviderGeoFeatureGroupExtension::extensionSetDisplayMode(const char* ModeName)
125
{
126
    if ( strcmp("Group",ModeName)==0 )
127
        getExtendedViewProvider()->setDisplayMaskMode("Group");
128

129
    ViewProviderGroupExtension::extensionSetDisplayMode( ModeName );
130
}
131

132
std::vector<std::string> ViewProviderGeoFeatureGroupExtension::extensionGetDisplayModes() const
133
{
134
    // get the modes of the father
135
    std::vector<std::string> StrList = ViewProviderGroupExtension::extensionGetDisplayModes();
136

137
    // add your own modes
138
    StrList.emplace_back("Group");
139

140
    return StrList;
141
}
142

143
void ViewProviderGeoFeatureGroupExtension::extensionUpdateData(const App::Property* prop)
144
{
145
    auto obj = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
146
    if (obj && prop == &obj->placement()) {
147
        getExtendedViewProvider()->setTransformation ( obj->placement().getValue().toMatrix() );
148
    }
149
    else {
150
        ViewProviderGroupExtension::extensionUpdateData ( prop );
151
    }
152
}
153

154
namespace Gui {
155
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderGeoFeatureGroupExtensionPython, Gui::ViewProviderGeoFeatureGroupExtension)
156

157
// explicit template instantiation
158
template class GuiExport ViewProviderExtensionPythonT<ViewProviderGeoFeatureGroupExtension>;
159
}
160

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.