@@ -22,14 +22,69 @@ struct XLNODEBULLET
2222 std::vector<unsigned long long > g;
2323};
2424
25+ struct VARIABLE
26+ {
27+ std::wstring n;
28+ std::wstring v;
29+
30+ void Ser (XML3::XMLElement& e)
31+ {
32+ e.vv (" n" ).SetWideValue (n.c_str ());
33+ e.vv (" v" ).SetWideValue (v.c_str ());
34+ }
35+
36+ void Unser (XML3::XMLElement& e)
37+ {
38+ n = e.vv (" n" ).GetWideValue ();
39+ v = e.vv (" v" ).GetWideValue ();
40+ }
41+ };
42+
2543struct PARAM
2644{
2745 std::wstring n;
28- float v = 0 ;
29- std::wstring string_param ;
46+ std::wstring v ;
47+ std::wstring save_v ;
3048 float minv = std::numeric_limits<float >::min();
3149 float maxv = std::numeric_limits<float >::max();
3250 std::vector<std::wstring> list_names;
51+
52+ const wchar_t * w ()
53+ {
54+ return v.c_str ();
55+ }
56+ operator const wchar_t * ()
57+ {
58+ return w ();
59+ }
60+ operator float ()
61+ {
62+ return std::stof (v.c_str ());
63+ }
64+ operator double ()
65+ {
66+ return std::stod (v.c_str ());
67+ }
68+ operator int ()
69+ {
70+ return std::stoi (v.c_str ());
71+ }
72+ operator unsigned int ()
73+ {
74+ return std::stoul (v.c_str ());
75+ }
76+ operator bool ()
77+ {
78+ return std::stoi (v.c_str ()) == 1 ;
79+ }
80+ operator long long ()
81+ {
82+ return std::stoll (v.c_str ());
83+ }
84+ operator unsigned long long ()
85+ {
86+ return std::stoull (v.c_str ());
87+ }
3388};
3489
3590struct XLNODE
@@ -355,22 +410,22 @@ struct XLNODE_ANY : public XLNODE
355410 }
356411 for (auto & p : Params)
357412 {
358- if (p.list_names .size () && (size_t )p. v < p.list_names .size ())
413+ if (p.list_names .size () && (int )p < p.list_names .size ())
359414 {
360- swprintf_s (t, 1000 , L" \r\n %s: %s" , p.n .c_str (), p.list_names [( size_t )p. v ].c_str ());
415+ swprintf_s (t, 1000 , L" \r\n %s: %s" , p.n .c_str (), p.list_names [p ].c_str ());
361416 }
362417 else
363418 if (p.minv <= -1 && p.maxv <= -1 )
364419 {
365- swprintf_s (t, 1000 , L" \r\n %s: %s" , p.n .c_str (), p.string_param . c_str ());
420+ swprintf_s (t, 1000 , L" \r\n %s: %s" , p.n .c_str (), p.w ());
366421 }
367422 else
368423 if (p.minv == 0 && p.maxv == 1 )
369424 {
370- swprintf_s (t, 1000 , L" \r\n %s: %s" , p.n .c_str (), p. v == 1 ? L" True" : L" False" );
425+ swprintf_s (t, 1000 , L" \r\n %s: %s" , p.n .c_str (), p ? L" True" : L" False" );
371426 }
372427 else
373- swprintf_s (t, 1000 , L" \r\n %s: %.2f" , p.n .c_str (), p. v );
428+ swprintf_s (t, 1000 , L" \r\n %s: %.2f" , p.n .c_str (), ( float )p );
374429 n += t;
375430 }
376431 return n;
@@ -399,7 +454,7 @@ struct XLNODE_ANY : public XLNODE
399454 {
400455 auto & pe = ee[" Params" ].AddElement (" Param" );
401456 pe.vv (" Name" ).SetWideValue (p.n .c_str ());
402- pe.vv (" Value" ).SetValueFloat (p.v );
457+ pe.vv (" Value" ).SetWideValue (p.w () );
403458 pe.vv (" Min" ).SetValueFloat (p.minv );
404459 pe.vv (" Max" ).SetValueFloat (p.maxv );
405460 for (auto & s : p.list_names )
@@ -415,7 +470,7 @@ struct XLNODE_ANY : public XLNODE
415470 {
416471 PARAM p;
417472 p.n = pe.vv (" Name" ).GetWideValue ();
418- p.v = pe.vv (" Value" ).GetValueFloat ();
473+ p.v = pe.vv (" Value" ).GetWideValue ();
419474 p.minv = pe.vv (" Min" ).GetValueFloat (std::numeric_limits<float >::min ());
420475 p.maxv = pe.vv (" Max" ).GetValueFloat (std::numeric_limits<float >::max ());
421476 for (auto & le : pe[" list" ])
@@ -433,7 +488,11 @@ struct XLNODE_CONSTANT : public XLNODE_ANY
433488
434489 XLNODE_CONSTANT () : XLNODE_ANY(0 , TYPE_CONSTANT)
435490 {
436- Params.push_back ({ L" Value" ,0 });
491+ PARAM p;
492+ p.n = L" Value" ;
493+ p.minv = -1 ;
494+ p.maxv = -1 ;
495+ Params.push_back (p);
437496 }
438497 std::vector<unsigned int > tensor_dims;
439498
@@ -593,7 +652,7 @@ struct XLOP : public XLNODE
593652 ee.vv (" Zoom" ).SetValueFloat (Zoom);
594653 for (auto & n : nodes)
595654 {
596- auto & ne = ee.AddElement (" Node" );
655+ auto & ne = ee[ " Nodes " ] .AddElement (" Node" );
597656 n->Ser (ne);
598657 }
599658 }
@@ -652,9 +711,9 @@ struct XLOP : public XLNODE
652711 virtual void Unser (XML3::XMLElement& e)
653712 {
654713 nodes.clear ();
655- for (size_t i = 0 ; i < e.GetChildrenNum (); i++)
714+ for (size_t i = 0 ; i < e[ " Nodes " ] .GetChildrenNum (); i++)
656715 {
657- auto & ne = e.GetChildren ()[i];
716+ auto & ne = e[ " Nodes " ] .GetChildren ()[i];
658717 auto n = Unser2 (*ne);
659718 nodes.push_back (n);
660719 }
@@ -665,47 +724,103 @@ struct XLOP : public XLNODE
665724
666725struct XL : public XLNODE
667726{
727+ std::wstring n;
668728 std::vector<XLOP> ops;
729+ std::vector<VARIABLE> variables;
669730 virtual std::wstring name () { return L" DML" ; }
670731 virtual std::wstring subname () { return L" " ; }
671732
672733 virtual void Ser (XML3::XMLElement& ee)
673734 {
735+ ee.vv (" n" ).SetWideValue (n.c_str ());
674736 for (auto & op : ops)
675737 {
676- auto & oe = ee.AddElement (" Operator" );
738+ auto & oe = ee[ " Operators " ] .AddElement (" Operator" );
677739 op.Ser (oe);
678740 }
741+
742+ for (auto & v : variables)
743+ {
744+ auto & nv = ee[" Variables" ].AddElement (" Variable" );
745+ v.Ser (nv);
746+ }
747+
679748 }
680749 virtual void Unser (XML3::XMLElement& e)
681750 {
751+ n = e.vv (" n" ).GetWideValue ();
682752 ops.clear ();
683- for (size_t i = 0 ; i < e.GetChildrenNum (); i++)
753+ for (size_t i = 0 ; i < e[ " Operators " ] .GetChildrenNum (); i++)
684754 {
685- auto & oe = e.GetChildren ()[i];
755+ auto & oe = e[ " Operators " ] .GetChildren ()[i];
686756 XLOP op;
687757 op.Unser (*oe);
688758 ops.push_back (op);
689759 }
690760
691761 for (auto & op : ops)
692762 {
693- for (auto & n : op.nodes )
763+ for (auto & no : op.nodes )
694764 {
695- for (auto & c : n ->children )
765+ for (auto & c : no ->children )
696766 {
697767 for (auto & gg : c.g )
698- nnn = std::max ((unsigned long long )abs (n ->ShareMemory ),std::max (nnn + 1 ,gg + 1 ));
768+ nnn = std::max ((unsigned long long )abs (no ->ShareMemory ),std::max (nnn + 1 ,gg + 1 ));
699769 }
700770 }
701771 }
772+
773+ variables.clear ();
774+ for (auto & ve : e[" Variables" ])
775+ {
776+ VARIABLE v;
777+ v.Unser (ve);
778+ variables.push_back (v);
779+ }
780+
702781 }
703782};
704783
705- inline bool Hit ( float x, float y, D2D1_RECT_F rc)
784+ struct PROJECT
706785{
707- return x >= rc.left && x <= rc.right && y >= rc.top && y <= rc.bottom ;
708- }
786+ std::vector<XL> xls;
787+ size_t iActive = 0 ;
788+ XL& xl ()
789+ {
790+ if (xls.empty ())
791+ {
792+ xls.push_back (XL ());
793+ return xls[0 ];
794+ }
795+ if (iActive < xls.size ())
796+ return xls[iActive];
797+ return xls[0 ];
798+ }
799+
800+ void Ser (XML3::XMLElement& e)
801+ {
802+ for (auto & xl : xls)
803+ {
804+ auto & xe = e[" Pages" ].AddElement (" Page" );
805+ xl.Ser (xe);
806+ }
807+ }
808+
809+ void Unser (XML3::XMLElement& e)
810+ {
811+ xls.clear ();
812+ for (size_t i = 0 ; i < e[" Pages" ].GetChildrenNum (); i++)
813+ {
814+ auto & xe = e[" Pages" ].GetChildren ()[i];
815+ XL xl;
816+ xl.Unser (*xe);
817+ xls.push_back (xl);
818+ }
819+ }
820+ };
821+
822+
823+
709824
710825namespace winrt ::DirectMLGraph::implementation
711826{
@@ -725,15 +840,14 @@ namespace winrt::DirectMLGraph::implementation
725840 void FullRefresh ();
726841
727842 ML ml;
728- XL xl;
843+ PROJECT prj;
844+ // XL xl;
729845 std::stack<XML3::XMLElement> undo_list;
730846 std::stack<XML3::XMLElement> redo_list;
731847 size_t ActiveOperator2 = (size_t )-1 ;
732848 std::shared_ptr<D2D> d2d;
733849 MLGraph ()
734850 {
735- // Xaml objects should not call InitializeComponent during construction.
736- // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
737851 }
738852
739853
@@ -796,6 +910,9 @@ namespace winrt::DirectMLGraph::implementation
796910 void OnCompile (IInspectable const &, IInspectable const &);
797911 void OnRun (IInspectable const &, IInspectable const &);
798912 void OnAddOp (IInspectable const &, IInspectable const &);
913+ void OnAddSet (IInspectable const &, IInspectable const &);
914+ void Tip (const wchar_t *);
915+ void OnAddVariable (IInspectable const &, IInspectable const &);
799916 void OnAddInput (IInspectable const &, IInspectable const &);
800917 void OnAddConstant (IInspectable const &, IInspectable const &);
801918 void OnAddOutput (IInspectable const &, IInspectable const &);
0 commit comments