SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
RenderingOptions.cpp
1 //
2 // RenderingOptions.cpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 //
26 
27 // Macro for getting rid of unused variables commonly for assert checking
28 #define _unused(x) ((void)(x))
29 
30 #include "SUAPI-CppWrapper/model/RenderingOptions.hpp"
31 #include "SUAPI-CppWrapper/String.hpp"
32 #include "SUAPI-CppWrapper/model/TypedValue.hpp"
33 #include <cassert>
34 
35 
36 namespace CW {
37 /// @private
38 RenderingOptions::RenderingOptions()
39  : m_rendering_options(SU_INVALID)
40 {
41 }
42 
43 /// @private
44 RenderingOptions::RenderingOptions(SURenderingOptionsRef ref)
45  : m_rendering_options(ref)
46 {
47 }
48 
49 RenderingOptions::~RenderingOptions()
50 {
51 }
52 
53 std::vector<std::string> RenderingOptions::get_keys() const
54 {
55  size_t len = 0, count = 0;
56  SUResult res = SU_ERROR_NONE;
57 
58  res = SURenderingOptionsGetNumKeys(m_rendering_options, &len);
59  assert(res == SU_ERROR_NONE);
60  assert(len > 0);
61 
62  std::vector<SUStringRef> refs(len, SU_INVALID);
63  for(auto i = 0; i < len; i++) {
64  res = SUStringCreate(&refs[i]);
65  assert(res == SU_ERROR_NONE);
66  }
67  res = SURenderingOptionsGetKeys(m_rendering_options, len, &refs[0], &count);
68  assert(res == SU_ERROR_NONE); _unused(res);
69  std::vector<std::string> keys;
70  for(auto ref : refs) {
71  keys.push_back(String(ref).std_string());
72  }
73  return keys;
74 }
75 
76 TypedValue RenderingOptions::get_value(const std::string& key) const
77 {
78  SUResult res = SU_ERROR_NONE;
79  SUTypedValueRef tval = SU_INVALID;
80  SUTypedValueRef* pTval = &tval;
81  res = SUTypedValueCreate(pTval);
82  assert(res == SU_ERROR_NONE);
83  res = SURenderingOptionsGetValue(m_rendering_options, key.c_str(), pTval);
84  assert(res == SU_ERROR_NONE); _unused(res);
85  return TypedValue(*pTval);
86 }
87 
88 bool CW::RenderingOptions::set_value(const std::string& key, const TypedValue& tval)
89 {
90  SUResult res = SU_ERROR_NONE;
91  SUTypedValueRef tref = tval.ref();
92  res = SURenderingOptionsSetValue(m_rendering_options, key.c_str(), tref);
93  if(res == SU_ERROR_NONE)
94  return true;
95  else
96  return false;
97 }
98 
99 } // namespace CW
Definition: Color.hpp:34