SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
InstancePath.hpp
1 //
2 // InstancePath.hpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 // Copyright (c) 2017 Tom Kaneko
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
18 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
26 //
27 
28 #ifndef InstancePath_hpp
29 #define InstancePath_hpp
30 
31 #include <stdio.h>
32 
33 #include <SketchUpAPI/model/instancepath.h>
34 
35 namespace CW {
36 
37 // Forward declarations
38 class ComponentInstance;
39 class Transformation;
40 class Entity;
41 class DrawingElement;
42 class String;
43 
44 
45 /*
46 * InstancePath wrapper
47 */
48 class InstancePath {
49  private:
50  SUInstancePathRef m_instance_path;
51 
52  static SUInstancePathRef create_instance_path();
53 
54  /**
55  * Creates a SUInstancePathRef derived from an existing InstancePath object.
56  * @param other - InstancePath object to derive the new SUInstancePathRef object from
57  * @return
58  */
59  static SUInstancePathRef copy_reference(const InstancePath& other);
60 
61  public:
62  /** Constructor for empty InstancePath value */
63  InstancePath();
64 
65  InstancePath(SUInstancePathRef instance_path);
66 
67  /** Copy constructor */
68  InstancePath(const InstancePath& other);
69 
70  /** Destructor */
71  ~InstancePath();
72 
73  /** Copy assignment operator */
74  InstancePath& operator=(const InstancePath& other);
75 
76  /*
77  * The class object can be converted to a SUInstancePathRef without loss of data.
78  */
79  SUInstancePathRef ref() const;
80  operator SUInstancePathRef() const;
81  operator SUInstancePathRef*();
82 
83  /**
84  * Pushes a ComponentInstance to an InstancePath.
85  * @param instance The component instance object.
86  * @return reference to this InstancePath
87  */
88  InstancePath& push(const ComponentInstance& instance);
89 
90  /**
91  * Pops the last ComponentInstance from an InstancePath.
92  * @return reference to this InstancePath
93  */
94  InstancePath& pop();
95 
96  /**
97  * Sets an Entity to an InstancePath.
98  * @param entity - The entity to be set as a leaf in instance path.
99  * @return reference to this InstancePath
100  */
101  InstancePath& set_leaf(const Entity& entity);
102 
103  /**
104  * Gets a path depth for InstancePath. It only counts the component instances in the path, so the leaf node is not counted.
105  * @return The depth of instance path object.
106  * TODO: This method should be const, but the C API has an error where SUInstancePathGetPathDepth is not const
107  */
108  size_t depth() const;
109 
110  /**
111  * Gets the full path depth (including the leaf) for InstancePath.
112  * @return The full depth of instance path object.
113  * TODO: This method should be const, but the C API has an error where SUInstancePathGetFullDepth is not const
114  */
115  size_t full_depth() const;
116 
117  /**
118  * Gets the transform for InstancePath.
119  * @return The transform from instance path
120  * TODO: This method should be const, but the C API has an error where SUInstancePathGetTransform is not const
121  */
123 
124  /**
125  * Gets the transform up to depth level for InstancePath.
126  * @param depth - The depth for getting transforms up to.
127  * @return The transform from instance path.
128  * TODO: This method should be const, but the C API has an error where SUInstancePathGetTransformAtDepth is not const
129  */
130  Transformation transformation_at_depth(size_t depth) const;
131 
132  /**
133  * Gets a component instance up to path depth level.
134  * @param depth - The depth for getting drawing element up to.
135  * @return The component instance on the instance path at that depth.
136  * TODO: This method should be const, but the C API has an error where SUInstancePathGetInstanceAtDepth is not const
137  */
138  ComponentInstance instance_at_depth(size_t depth) const;
139 
140 
141  /**
142  * Gets a leaf from an instance path as an entity object.
143  * @return The leaf entity from an instance path.
144  * TODO: This method should be const, but the C API has an error where SUInstancePathGetLeafAsEntity is not const
145  */
146  Entity leaf_entity() const;
147 
148  /**
149  * Gets a leaf from an entity path as a drawing element object.
150  * @return The leaf DrawingElement from an instance path.
151  * TODO: This method should be const, but the C API has an error where SUInstancePathGetLeaf is not const
152  */
153  DrawingElement leaf() const;
154 
155  /**
156  * Validates an instance path.
157  * @return Whether the instance path is valid or not.
158  * TODO: This method should be const, but the C API has an error where SUInstancePathIsValid is not const
159  */
160  bool valid() const;
161 
162  /**
163  * Checks if an instance path is empty.
164  * @return Whether the instance path is empty or not.
165  * TODO: This method should be const, but the C API has an error where SUInstancePathIsEmpty is not const
166  */
167  bool empty() const;
168 
169  /**
170  * Checks if instance path contains a particular entity.
171  @param entity - The entity object.
172  @return Whether the instance path contains the entity or not.
173  * TODO: This method should be const, but the C API has an error where SUInstancePathContains is not const
174  */
175  bool contains(const Entity& entity) const;
176 
177  /**
178  * Retrieves the full persistent id for a given instance path.
179  * @return A String of the persistent id (or its full depth?).
180  * TODO: This method should be const, but the C API has an error where SUInstancePathGetPersistentID is not const
181  */
182  String persistent_id() const;
183 
184  /**
185  * Retrieves the persistent id of an entity up to depth level in a given instance path.
186  * @param depth - The depth for getting persistent id up to.
187  * @return The persistent id.
188  * TODO: This method should be const, but the C API has an error where SUInstancePathGetPersistentIDAtDepth is not const
189  */
190  String persistent_id_at_depth(size_t depth) const;
191 
192 };
193 
194 } /* namespace CW */
195 
196 #endif /* InstancePath_hpp */
size_t depth() const
String persistent_id_at_depth(size_t depth) const
InstancePath & set_leaf(const Entity &entity)
Transformation total_transformation() const
bool empty() const
bool contains(const Entity &entity) const
InstancePath & operator=(const InstancePath &other)
size_t full_depth() const
Transformation transformation_at_depth(size_t depth) const
InstancePath & push(const ComponentInstance &instance)
ComponentInstance instance_at_depth(size_t depth) const
String persistent_id() const
Definition: Color.hpp:34
DrawingElement leaf() const
InstancePath & pop()
Entity leaf_entity() const
bool valid() const