File size: 5,603 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
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
 *                                                                          *
 *   Copyright (c) 2024 wandererfan <wandererfan@gmail.com>                 *
 *                                                                          *
 *   This file is part of FreeCAD.                                          *
 *                                                                          *
 *   FreeCAD is free software: you can redistribute it and/or modify it     *
 *   under the terms of the GNU Lesser General Public License as            *
 *   published by the Free Software Foundation, either version 2.1 of the   *
 *   License, or (at your option) any later version.                        *
 *                                                                          *
 *   FreeCAD 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       *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU Lesser General Public       *
 *   License along with FreeCAD. If not, see                                *
 *   <https://www.gnu.org/licenses/>.                                       *
 *                                                                          *
 ***************************************************************************/

#ifndef MEASURE_SHAPEFINDER_H
#define MEASURE_SHAPEFINDER_H

#include <Mod/Measure/MeasureGlobal.h>

#include <TopoDS_Shape.hxx>

#include <App/DocumentObject.h>
#include <App/DocumentObserver.h>
#include <Base/Placement.h>
#include <Base/Matrix.h>

#include <Mod/Part/App/TopoShape.h>

#include "SubnameHelper.h"

namespace Measure
{

//! a class to hold the result of resolving a selection into the actual target object
//! and traditional subElement name (Vertex1)

class MeasureExport ResolveResult
{
public:
    ResolveResult();
    ResolveResult(
        const App::DocumentObject* realTarget,
        const std::string& shortSubName,
        const App::DocumentObject* targetParent
    );

    App::DocumentObject& getTarget() const;
    std::string getShortSub() const;
    App::DocumentObject& getTargetParent() const;

private:
    App::SubObjectT m_target;
    App::DocumentObjectT m_targetParent;
};


//! a class to obtain the located shape pointed at by a selection
class MeasureExport ShapeFinder: public SubnameHelper
{
public:
    static TopoDS_Shape getLocatedShape(
        const App::DocumentObject& rootObject,
        const std::string& leafSub
    );
    static Part::TopoShape getLocatedTopoShape(
        const App::DocumentObject& rootObject,
        const std::string& leafSub
    );


    static std::pair<Base::Placement, Base::Matrix4D> getGlobalTransform(
        const App::DocumentObject& rootObject,
        const std::string& leafSub
    );
    static std::pair<Base::Placement, Base::Matrix4D> getGlobalTransform(
        const App::DocumentObject* cursorObject
    );

    static void crawlPlacementChain(
        std::vector<Base::Placement>& plmStack,
        std::vector<Base::Matrix4D>& scaleStack,
        const App::DocumentObject& rootObj,
        const std::string& leafSub
    );

    static ResolveResult resolveSelection(
        const App::DocumentObject& selectObj,
        const std::string& selectLongSub
    );

    static Base::Placement getPlacement(const App::DocumentObject* root);
    static Base::Matrix4D getScale(const App::DocumentObject* root);

    static bool isLinkLike(const App::DocumentObject* obj);
    static std::string PlacementAsString(const Base::Placement& inPlacement);
    static std::string LocationAsString(const TopLoc_Location& location);

    static TopoDS_Shape transformShape(
        TopoDS_Shape& inShape,
        const Base::Placement& placement,
        const Base::Matrix4D& scaler
    );
    static TopoDS_Shape stripInfiniteShapes(const TopoDS_Shape& inShape);
    static bool isShapeReallyNull(const TopoDS_Shape& shape);

    static std::pair<Base::Placement, Base::Matrix4D> sumTransforms(
        const std::vector<Base::Placement>& plmStack,
        const std::vector<Base::Matrix4D>& scaleStack
    );
    static App::DocumentObject* getLinkAttachParent(const App::DocumentObject* attachedObject);
    static Base::Placement getAttachedPlacement(const App::DocumentObject* cursorObject);

    static std::string getFullPath(const App::DocumentObject* object);
    static std::vector<App::DocumentObject*> getGeometryRootObjects(const App::Document* doc);
    static std::vector<std::list<App::DocumentObject*>> getGeometryPathsFromOutList(
        const App::DocumentObject* object
    );


private:
    static bool ignoreModule(const std::string& moduleName);
    static bool ignoreObject(const App::DocumentObject* object);
    static bool ignoreLinkAttachedObject(
        const App::DocumentObject* object,
        const App::DocumentObject* inlistObject
    );
    static std::vector<App::DocumentObject*> tidyInList(
        const std::vector<App::DocumentObject*>& inlist
    );
    static std::vector<App::DocumentObject*> tidyInListAttachment(
        const App::DocumentObject* owner,
        const std::vector<App::DocumentObject*>& inlist
    );
};

}  // namespace Measure

#endif  // MEASURE_SHAPEFINDER_H