File size: 5,616 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
/******************************************************************************

 *   Copyright (c) 2012 Konstantinos Poulios <logari81@gmail.com>             *

 *                                                                            *

 *   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                                   *

 *                                                                            *

 ******************************************************************************/


#ifndef GUI_ReferenceSelection_H
#define GUI_ReferenceSelection_H

#include <Gui/Selection/SelectionFilter.h>
#include <Mod/PartDesign/Gui/EnumFlags.h>

namespace App
{
class OriginGroupExtension;
}
namespace PartDesign
{
class Body;
}
namespace PartDesignGui
{

class ReferenceSelection: public Gui::SelectionFilterGate
{
    const App::DocumentObject* support;
    AllowSelectionFlags type;

public:
    ReferenceSelection(const App::DocumentObject* support_, AllowSelectionFlags type)
        : Gui::SelectionFilterGate(nullPointer())
        , support(support_)
        , type(type)
    {}
    /**

     * Allow the user to pick only edges or faces (or both) from the defined support

     * Optionally restrict the selection to planar edges/faces

     */
    bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override;

private:
    PartDesign::Body* getBody() const;
    App::OriginGroupExtension* getOriginGroupExtension(PartDesign::Body* body) const;
    bool allowOrigin(

        PartDesign::Body* body,

        App::OriginGroupExtension* originGroup,

        App::DocumentObject* pObj

    ) const;
    bool allowDatum(PartDesign::Body* body, App::DocumentObject* pObj) const;
    bool allowPartFeature(App::DocumentObject* pObj, const char* sSubName) const;
    bool isEdge(App::DocumentObject* pObj, const char* sSubName) const;
    bool isFace(App::DocumentObject* pObj, const char* sSubName) const;
    bool isCircle(App::DocumentObject* pObj, const char* sSubName) const;
};

class NoDependentsSelection: public Gui::SelectionFilterGate
{
    const App::DocumentObject* support;

public:
    NoDependentsSelection(const App::DocumentObject* support_)
        : Gui::SelectionFilterGate(nullPointer())
        , support(support_)
    {}
    /**

     * Allow the user to pick only objects which are not in objs getDependencyList

     */
    bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override;
};

class CombineSelectionFilterGates: public Gui::SelectionFilterGate
{
    std::unique_ptr<Gui::SelectionFilterGate> filter1;
    std::unique_ptr<Gui::SelectionFilterGate> filter2;

public:
    CombineSelectionFilterGates(
        std::unique_ptr<Gui::SelectionFilterGate>& filter1_,
        std::unique_ptr<Gui::SelectionFilterGate>& filter2_
    )
        : Gui::SelectionFilterGate(nullPointer())
        , filter1(std::move(filter1_))
        , filter2(std::move(filter2_))
    {}
    bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override;
};
// Convenience methods
/// Extract reference from Selection
bool getReferencedSelection(

    const App::DocumentObject* thisObj,

    const Gui::SelectionChanges& msg,

    App::DocumentObject*& selObj,

    std::vector<std::string>& selSub

);
/// Return reference as string for UI elements (format <obj>:<subelement>
QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub);
/// Return reference as string for python in the format (<obj> ["sub1", "sub2", ...])
std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& subs);
/// Return reference as string for python in the format (<obj> ["sub"?])
std::string buildLinkSingleSubPythonStr(

    const App::DocumentObject* obj,

    const std::vector<std::string>& subs

);
/// Return reference as string for python in the format [obj1, obj2, ...,]
std::string buildLinkListPythonStr(const std::vector<App::DocumentObject*>& objs);
/// Returns sub reference list as a python string in the format [(obj1,"sub1"),(obj2,"sub2"),...]
std::string buildLinkSubListPythonStr(

    const std::vector<App::DocumentObject*>& objs,

    const std::vector<std::string>& subs

);
}  // namespace PartDesignGui

#endif  // GUI_ReferenceSelection_H