@@ -42,119 +42,63 @@ along with sofaqtquick. If not, see <http://www.gnu.org/licenses/>.
4242
4343// //////////////////////// FORWARD DECLARATION ///////////////////////////
4444namespace sofa {
45- namespace defaulttype {
46- class AbstractTypeInfo ;
47- }
48- namespace core {
49- namespace objectmodel {
50- class BaseData ;
51-
52-
53- class SOFAPYTHON3_API PrefabLink
54- {
55- public:
56- PrefabLink () {}
57- PrefabLink (const Base::SPtr& targetBase) { m_targetBase = targetBase; }
58- PrefabLink (BaseLink* targetLink) { m_targetBase = targetLink->getLinkedBase (); }
59- PrefabLink (const std::string& targetPath) { m_targetPath = targetPath; }
60-
61- const Base::SPtr& getTargetBase () const { return m_targetBase; }
62- void setTargetBase (const Base::SPtr& targetBase) { m_targetBase = targetBase; }
63-
64- const std::string& getTargetPath () const { return m_targetPath; }
65- void setTargetPath (const std::string& targetPath) { m_targetPath = targetPath; }
66-
67- friend std::ostream& operator << ( std::ostream& out, const PrefabLink& l)
68- {
69- if (l.getTargetBase ())
70- {
71- auto bn = l.getTargetBase ()->toBaseNode ();
72- auto bo = l.getTargetBase ()->toBaseObject ();
73- out << " @" + (bn ? bn->getPathName () : bo->getPathName ());
74- }
75- out << l.getTargetPath ();
76- return out;
77- }
78-
79- friend std::istream& operator >> ( std::istream& in, PrefabLink& l)
80- {
81- std::string s;
82- in >> s;
83- l.setTargetPath (s);
84- return in;
85- }
86-
87- private:
88- Base::SPtr m_targetBase { nullptr };
89- std::string m_targetPath {" " };
90- };
91-
92- class SOFAPYTHON3_API DataLink : public Data<PrefabLink>
93- {
94- typedef Data<PrefabLink> Inherit;
95-
96- DataLink ( const std::string& helpMsg=" " , bool isDisplayed=true , bool isReadOnly=false )
97- : Inherit(helpMsg, isDisplayed, isReadOnly)
98- {
99- }
100-
101- DataLink ( const std::string& value, const std::string& helpMsg=" " , bool isDisplayed=true , bool isReadOnly=false )
102- : Inherit(value, helpMsg, isDisplayed, isReadOnly)
103- {
104- }
105-
106- explicit DataLink (const BaseData::BaseInitData& init)
107- : Inherit(init)
108- {
109- }
110-
111- const PrefabLink& getValue () const
112- {
113- updateIfDirty ();
114- if (m_value.getValue ().getTargetBase ()) return m_value.getValue ();
115-
116- auto self = const_cast <DataLink*>(this );
117-
118- Base* dst = nullptr ;
119- this ->getOwner ()->findLinkDest (dst, self->m_value .getValue ().getTargetPath (), nullptr );
120- if (dst) {
121- auto edit = self->m_value .beginEdit ();
122- edit->setTargetBase (dst);
123- edit->setTargetPath (" " );
124- self->m_value .endEdit ();
125- }
126- return m_value.getValue ();
127- }
128-
129- std::string getValueString () const
130- {
131- const auto & ptr = getValue ();
132- if (ptr.getTargetBase ())
133- {
134- auto bn = ptr.getTargetBase ()->toBaseNode ();
135- auto bo = ptr.getTargetBase ()->toBaseObject ();
136- return " @" + (bn ? bn->getPathName () : bo->getPathName ());
137- }
138- return ptr.getTargetPath ();
139- }
140-
141-
142- bool read (const std::string& value)
143- {
144- Base* dst;
145- auto data = m_value.beginEdit ();
146- if (this ->getOwner ()->findLinkDest (dst, value, nullptr ) && dst != nullptr )
147- data->setTargetBase (dst);
148- else {
149- data->setTargetBase (nullptr );
150- data->setTargetPath (value);
151- }
152- return true ;
153- }
154- };
45+ namespace defaulttype {
46+ class AbstractTypeInfo ;
47+ }
48+ namespace core {
49+ namespace objectmodel {
50+ class BaseData ;
51+
52+
53+ class SOFAPYTHON3_API PrefabLink
54+ {
55+ public:
56+ PrefabLink () {}
57+ PrefabLink (const Base::SPtr& targetBase) { m_targetBase = targetBase; }
58+ PrefabLink (BaseLink* targetLink) { m_targetBase = targetLink->getLinkedBase (); }
59+ PrefabLink (const std::string& targetPath) { m_targetPath = targetPath; }
15560
61+ const Base::SPtr& getTargetBase () const { return m_targetBase; }
62+ void setTargetBase (const Base::SPtr& targetBase) { m_targetBase = targetBase; }
63+
64+ const std::string& getTargetPath () const { return m_targetPath; }
65+ void setTargetPath (const std::string& targetPath) { m_targetPath = targetPath; }
66+
67+ friend std::ostream& operator << ( std::ostream& out, const PrefabLink& l)
68+ {
69+ if (l.getTargetBase ())
70+ {
71+ auto bn = l.getTargetBase ()->toBaseNode ();
72+ auto bo = l.getTargetBase ()->toBaseObject ();
73+ out << " @" + (bn ? bn->getPathName () : bo->getPathName ());
15674 }
75+ out << l.getTargetPath ();
76+ return out;
77+ }
78+
79+ friend std::istream& operator >> ( std::istream& in, PrefabLink& l)
80+ {
81+ std::string s;
82+ in >> s;
83+ l.setTargetPath (s);
84+ return in;
15785 }
86+
87+ private:
88+ Base::SPtr m_targetBase { nullptr };
89+ std::string m_targetPath {" " };
90+ };
91+ }
92+ }
93+ namespace defaulttype
94+ {
95+ template <>
96+ struct DataTypeName <core::objectmodel::PrefabLink>
97+ {
98+ static const char * name () { return " PrefabLink" ; }
99+ };
100+
101+ }
158102}
159103
160104// ///////////////////////////// DECLARATION //////////////////////////////
@@ -192,7 +136,7 @@ template <typename T> class py_shared_ptr : public sofa::core::sptr<T>
192136
193137SOFAPYTHON3_API void setItem2D (py::array a, py::slice slice, py::object o);
194138SOFAPYTHON3_API void setItem2D (py::array a, const py::slice& slice,
195- const py::slice& slice1, py::object o);
139+ const py::slice& slice1, py::object o);
196140SOFAPYTHON3_API void setItem1D (py::array a, py::slice slice, py::object o);
197141SOFAPYTHON3_API void setItem (py::array a, py::slice slice, py::object value);
198142
@@ -216,11 +160,16 @@ void SOFAPYTHON3_API copyFromListScalar(BaseData& d, const AbstractTypeInfo& nfo
216160
217161std::string SOFAPYTHON3_API toSofaParsableString (const py::handle& p);
218162
219- // py::object SOFAPYTHON3_API dataToPython(BaseData* d);
220-
221163// / RVO optimized function. Don't care about copy on the return code.
222164void SOFAPYTHON3_API fillBaseObjectdescription (sofa::core::objectmodel::BaseObjectDescription& desc,
223- const py::dict& dict);
165+ const py::dict& dict);
166+
167+ // / Split the content of the dictionnary 'dict' in three set.
168+ // / On containing the data to parent, one containing the data to copy and on containing the data to parse in the BaseObjectDescription
169+ void SOFAPYTHON3_API processKwargsForObjectCreation (const py::dict dict,
170+ py::list& parametersToLink,
171+ py::list& parametersToCopy,
172+ sofa::core::objectmodel::BaseObjectDescription& parametersAsString);
224173
225174template <typename T>
226175void copyScalar (BaseData* a, const AbstractTypeInfo& nfo, py::array_t <T, py::array::c_style> src)
0 commit comments