11# Standard library imports 
2- import  json 
32import  os 
43
54# Third party imports 
65import  vtk 
7- from  vtk .web  import  protocols  as  vtk_protocols 
8- from  vtkmodules .vtkIOImage  import  vtkPNGWriter , vtkJPEGWriter 
9- from  vtkmodules .vtkRenderingCore  import  (vtkWindowToImageFilter )
106from  wslink  import  register  as  exportRpc 
117
128# Local application imports 
139from  opengeodeweb_viewer .utils_functions  import  get_schemas_dict , validate_schema 
1410from  opengeodeweb_viewer .object .object_methods  import  VtkObjectView 
1511
1612class  VtkMeshView (VtkObjectView ):
17-     prefix  =  "opengeodeweb_viewer.mesh." 
18-     schemas_dict  =  get_schemas_dict (os .path .join (os .path .dirname (__file__ ), "schemas" ))
13+     mesh_prefix  =  "opengeodeweb_viewer.mesh." 
14+     mesh_schemas_dict  =  get_schemas_dict (os .path .join (os .path .dirname (__file__ ), "schemas" ))
1915
2016    def  __init__ (self ):
2117        super ().__init__ ()
2218
23-     @exportRpc (prefix  +  schemas_dict ["register" ]["rpc" ]) 
19+     @exportRpc (mesh_prefix  +  mesh_schemas_dict ["register" ]["rpc" ]) 
2420    def  registerMesh (self , params ):
25-         print (self .schemas_dict ["register" ]["rpc" ], f"{ params = }  " , flush = True )
26-         validate_schema (params , self .schemas_dict ["register" ])
21+         print (self .mesh_prefix   +   self . mesh_schemas_dict ["register" ]["rpc" ], f"{ params = }  " , flush = True )
22+         validate_schema (params , self .mesh_schemas_dict ["register" ])
2723        id  =  params ["id" ]
2824        file_name  =  params ["file_name" ]
2925        try :
@@ -35,69 +31,38 @@ def registerMesh(self, params):
3531        except  Exception  as  e :
3632            print ("error : " , str (e ), flush = True )
3733
38-     @exportRpc (prefix  +  schemas_dict ["deregister" ]["rpc" ]) 
34+     @exportRpc (mesh_prefix  +  mesh_schemas_dict ["deregister" ]["rpc" ]) 
3935    def  deregisterMesh (self , params ):
40-         print (self .schemas_dict ["deregister" ]["rpc" ], f"{ params = }  " , flush = True )
41-         validate_schema (params , self .schemas_dict ["deregister" ])
36+         print (self .mesh_prefix   +   self . mesh_schemas_dict ["deregister" ]["rpc" ], f"{ params = }  " , flush = True )
37+         validate_schema (params , self .mesh_schemas_dict ["deregister" ])
4238        id  =  params ["id" ]
4339        self .deregisterObject (id )
4440
45-     @exportRpc (prefix  +  schemas_dict [ "set_visibility " ]["rpc" ]) 
41+     @exportRpc (mesh_prefix  +  mesh_schemas_dict [ "visibility " ]["rpc" ]) 
4642    def  SetMeshVisibility (self , params ):
47-         print (self .schemas_dict [ "set_visibility " ]["rpc" ], f"{ params = }  " , flush = True )
48-         validate_schema (params , self .schemas_dict [ "set_visibility " ])
43+         print (self .mesh_prefix   +   self . mesh_schemas_dict [ "visibility " ]["rpc" ], f"{ params = }  " , flush = True )
44+         validate_schema (params , self .mesh_schemas_dict [ "visibility " ])
4945        id  =  params ["id" ]
5046        visibility  =  bool (params ["visibility" ])
5147        self .SetVisibility (id , visibility )
5248
53-     @exportRpc (prefix  +  schemas_dict [ "set_opacity " ]["rpc" ]) 
49+     @exportRpc (mesh_prefix  +  mesh_schemas_dict [ "opacity " ]["rpc" ]) 
5450    def  setMeshOpacity (self , params ):
55-         print (self .schemas_dict [ "set_opacity " ]["rpc" ], f"{ params = }  " , flush = True )
56-         validate_schema (params , self .schemas_dict [ "set_opacity " ])
51+         print (self .mesh_prefix   +   self . mesh_schemas_dict [ "opacity " ]["rpc" ], f"{ params = }  " , flush = True )
52+         validate_schema (params , self .mesh_schemas_dict [ "opacity " ])
5753        id  =  params ["id" ]
5854        opacity  =  float (params ["opacity" ])
5955        self .SetOpacity (id , opacity )
6056
61-     @exportRpc (prefix  +  schemas_dict ["set_edge_visibility" ]["rpc" ]) 
62-     def  setMeshEdgeVisibility (self , params ):
63-         print (self .schemas_dict ["set_edge_visibility" ]["rpc" ], f"{ params = }  " , flush = True )
64-         validate_schema (params , self .schemas_dict ["set_edge_visibility" ])
65-         id  =  params ["id" ]
66-         visibility  =  bool (params ["visibility" ])
67-         self .SetEdgeVisibility (id , visibility )
68- 
69-     @exportRpc (prefix  +  schemas_dict ["set_point_visibility" ]["rpc" ]) 
70-     def  setMeshPointVisibility (self , params ):
71-         print (self .schemas_dict ["set_point_visibility" ]["rpc" ], f"{ params = }  " , flush = True )
72-         validate_schema (params , self .schemas_dict ["set_point_visibility" ])
73-         id  =  params ["id" ]
74-         visibility  =  bool (params ["visibility" ])
75-         self .SetVertexVisibility (id , visibility )
76- 
77-     @exportRpc (prefix  +  schemas_dict ["set_point_size" ]["rpc" ]) 
78-     def  setMeshPointSize (self , params ):
79-         print (self .schemas_dict ["set_point_size" ]["rpc" ], f"{ params = }  " , flush = True )
80-         validate_schema (params , self .schemas_dict ["set_point_size" ])
81-         id  =  params ["id" ]
82-         size  =  float (params ["size" ])
83-         self .SetPointSize (id , size )
84- 
85-     @exportRpc (prefix  +  schemas_dict ["set_color" ]["rpc" ]) 
57+     @exportRpc (mesh_prefix  +  mesh_schemas_dict ["color" ]["rpc" ]) 
8658    def  setMeshColor (self , params ):
87-         print (self .schemas_dict [ "set_color " ]["rpc" ], f"{ params = }  " , flush = True )
88-         validate_schema (params , self .schemas_dict [ "set_color " ])
59+         print (self .mesh_prefix   +   self . mesh_schemas_dict [ "color " ]["rpc" ], f"{ params = }  " , flush = True )
60+         validate_schema (params , self .mesh_schemas_dict [ "color " ])
8961        id  =  params ["id" ]
90-         red  =  params ["red" ]
91-         green  =  params ["green" ]
92-         blue  =  params ["blue" ]
62+         red , green , blue  =  params ["color" ]["r" ], params ["color" ]["g" ], params ["color" ]["b" ]
9363        self .SetColor (id , red , green , blue )
9464
95-     @exportRpc (prefix  +  schemas_dict ["display_vertex_attribute" ]["rpc" ]) 
96-     def  setVertexAttribute (self , params ):
97-         print (self .schemas_dict ["display_vertex_attribute" ]["rpc" ], f"{ params = }  " , flush = True )
98-         validate_schema (params , self .schemas_dict ["display_vertex_attribute" ])
99-         id  =  params ["id" ]
100-         name  =  params ["name" ]
65+     def  setMeshVertexAttribute (self , id , name ):
10166        reader  =  self .get_object (id )["reader" ]
10267        points  =  reader .GetOutput ().GetPointData ()
10368        points .SetActiveScalars (name )
@@ -107,12 +72,7 @@ def setVertexAttribute(self, params):
10772        mapper .SetScalarRange (points .GetScalars ().GetRange ())
10873        self .render ()
10974
110-     @exportRpc (prefix  +  schemas_dict ["display_polygon_attribute" ]["rpc" ]) 
111-     def  setPolygonAttribute (self , params ):
112-         print (self .schemas_dict ["display_polygon_attribute" ]["rpc" ], f"{ params = }  " , flush = True )
113-         validate_schema (params , self .schemas_dict ["display_polygon_attribute" ])
114-         id  =  params ["id" ]
115-         name  =  params ["name" ]
75+     def  setMeshPolygonAttribute (self , id , name ):
11676        reader  =  self .get_object (id )["reader" ]
11777        cells  =  reader .GetOutput ().GetCellData ()
11878        cells .SetActiveScalars (name )
0 commit comments