File size: 6,282 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# ***************************************************************************
# *   Copyright (c) 2025 Stefan Tröger <stefantroeger@gmx.net>              *
# *                                                                         *
# *   This file is part of the FreeCAD CAx development system.              *
# *                                                                         *
# *   This program is free software; you can redistribute it and/or modify  *
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
# *   as published by the Free Software Foundation; either version 2 of     *
# *   the License, or (at your option) any later version.                   *
# *   for detail see the LICENCE text file.                                 *
# *                                                                         *
# *   This program 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 program; if not, write to the Free Software   *
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
# *   USA                                                                   *
# *                                                                         *
# ***************************************************************************

__title__ = "FreeCAD FEM postprocessing ldata view and extraction widget"
__author__ = "Stefan Tröger"
__url__ = "https://www.freecad.org"

## @package data_extraction
#  \ingroup FEM
#  \brief A widget for data extraction. Used in the PostObject task panel.

from . import vtk_table_view

from PySide import QtCore, QtGui

from vtkmodules.vtkCommonCore import vtkVersion
from vtkmodules.vtkCommonDataModel import vtkTable
from vtkmodules.vtkFiltersGeneral import vtkSplitColumnComponents

from Fem import vtkVersionCheck

if vtkVersionCheck(
    vtkVersion.GetVTKMajorVersion(), vtkVersion.GetVTKMinorVersion()
) >= vtkVersionCheck(9, 3):
    from vtkmodules.vtkFiltersCore import vtkAttributeDataToTableFilter
else:
    from vtkmodules.vtkInfovisCore import vtkDataObjectToTable


import FreeCAD
import FreeCADGui

import femobjects.base_fempostextractors as extr
from femtaskpanels.base_fempostpanel import _BasePostTaskPanel

from . import extract_link_view

ExtractLinkView = extract_link_view.ExtractLinkView


class DataExtraction(_BasePostTaskPanel):
    # The class is not a widget itself, but provides a widget. It implements
    # all required callbacks for the widget and the task dialog.
    # Note: This object is created and used from c++! See PostTaskExtraction

    def __init__(self, vobj):

        super().__init__(vobj.Object)

        self.ViewObject = vobj
        self.Object = vobj.Object

        self.widget = FreeCADGui.PySideUic.loadUi(
            FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/TaskPostExtraction.ui"
        )

        # connect all signals as required
        self.widget.Data.clicked.connect(self.showData)
        self.widget.Summary.clicked.connect(self.showSummary)

        # setup the data models
        self.data_model = vtk_table_view.VtkTableModel()
        self.summary_model = vtk_table_view.VtkTableSummaryModel()

        # generate the data
        self.onPostDataChanged(self.Object)

        # setup the extraction widget
        self._extraction_view = ExtractLinkView(self.Object, True, self)
        self.widget.layout().addSpacing(self.widget.Data.size().height() / 3)
        self.widget.layout().addWidget(self._extraction_view)
        self._extraction_view.repopulate()

    @QtCore.Slot()
    def showData(self):

        dialog = QtGui.QDialog(self.widget)
        dialog.setWindowTitle(f"Data of {self.Object.Label}")
        widget = vtk_table_view.VtkTableView(self.data_model)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(widget)
        layout.setContentsMargins(0, 0, 0, 0)

        dialog.setLayout(layout)
        dialog.resize(1500, 900)
        dialog.show()

    @QtCore.Slot()
    def showSummary(self):

        dialog = QtGui.QDialog(self.widget)
        dialog.setWindowTitle(f"Data Summary of {self.Object.Label}")
        widget = vtk_table_view.VtkTableView(self.summary_model)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(widget)
        layout.setContentsMargins(0, 0, 0, 0)

        dialog.setLayout(layout)
        dialog.resize(600, 900)
        dialog.show()

    def isGuiTaskOnly(self):
        # If all panels return true it omits the Apply button in the dialog
        return True

    def onPostDataChanged(self, obj):

        algo = obj.getOutputAlgorithm()
        if not algo:
            self.data_model.setTable(vtkTable())

        if vtkVersionCheck(
            vtkVersion.GetVTKMajorVersion(), vtkVersion.GetVTKMinorVersion()
        ) >= vtkVersionCheck(9, 3):
            filter = vtkAttributeDataToTableFilter()
        else:
            filter = vtkDataObjectToTable()
            filter.SetFieldType(vtkDataObjectToTable.POINT_DATA)

        filter.SetInputConnection(0, algo.GetOutputPort(0))
        filter.Update()
        table = filter.GetOutputDataObject(0)

        # add the points
        points = algo.GetOutputDataObject(0).GetPoints().GetData()
        table.AddColumn(points)

        # split the components
        splitter = vtkSplitColumnComponents()
        splitter.SetNamingModeToNamesWithParens()
        splitter.SetInputData(0, table)

        splitter.Update()
        table = splitter.GetOutputDataObject(0)

        self.data_model.setTable(table)
        self.summary_model.setTable(table)

    def apply(self):
        pass

    def initiallyCollapsed(self):
        # if we do not have any extractions to show we hide initially to remove clutter

        for obj in self.Object.InList:
            if extr.is_extractor_object(obj):
                return False

        return True