Skip to content

Commit

Permalink
refactor(model): add grid_display_mode and add legend in vtkjs
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-chauhan committed Feb 16, 2022
1 parent 3fa7665 commit 652b3f0
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions honeybee_vtk/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def to_vtkjs(self, *, folder: str = '.', name: str = None, config: str = None,
validation: Boolean to indicate whether to validate the data before loading.
Defaults to False.
model_display_mode: Display mode for the model. Defaults to shaded.
model_display_mode: Display mode for the Grids. Defaults to shaded.
grid_display_mode: Display mode for the Grids. Defaults to shaded.
Returns:
A text string representing the file path to the vtkjs file.
Expand Down Expand Up @@ -422,7 +422,8 @@ def to_vtkjs(self, *, folder: str = '.', name: str = None, config: str = None,
def to_html(self, *, folder: str = '.', name: str = None, show: bool = False,
config: str = None,
validation: bool = False,
display_mode: DisplayMode = DisplayMode.Shaded) -> str:
model_display_mode: DisplayMode = DisplayMode.Shaded,
grid_display_mode: DisplayMode = DisplayMode.Shaded) -> str:
"""Write the model to an HTML file.
Write your honeybee-vtk model to an HTML file that you can open in any modern
Expand All @@ -436,12 +437,13 @@ def to_html(self, *, folder: str = '.', name: str = None, show: bool = False,
default browser. Defaults to False
config: Path to the config file in JSON format. Defaults to None.
validation: Boolean to indicate whether to validate the data before loading.
display_mode: Display mode for the model. Defaults to shaded.
model_display_mode: Display mode for the model. Defaults to shaded.
grid_display_mode: Display mode for the Grids. Defaults to shaded.
Returns:
A text string representing the file path to the HTML file.
"""
self.update_display_mode(display_mode)
self.update_display_mode(model_display_mode)
# Name of the html file
file_name = name or 'model'
# Set the target folder
Expand All @@ -451,7 +453,8 @@ def to_html(self, *, folder: str = '.', name: str = None, show: bool = False,
# Set temp folder to do the operation
temp_folder = tempfile.mkdtemp()
vtkjs_file = self.to_vtkjs(
folder=temp_folder, config=config, validation=validation)
folder=temp_folder, config=config, validation=validation,
model_display_mode=model_display_mode, grid_display_mode=grid_display_mode)
temp_html_file = add_data_to_viewer(vtkjs_file)
shutil.copy(temp_html_file, html_file)
try:
Expand All @@ -465,7 +468,8 @@ def to_html(self, *, folder: str = '.', name: str = None, show: bool = False,
def to_files(self, *, folder: str = '.', name: str = None,
writer: VTKWriters = VTKWriters.binary, config: str = None,
validation: bool = False,
display_mode: DisplayMode = DisplayMode.Shaded) -> str:
model_display_mode: DisplayMode = DisplayMode.Shaded,
grid_display_mode: DisplayMode = DisplayMode.Shaded) -> str:
"""
Write a .zip of VTK/VTP files.
Expand All @@ -478,16 +482,22 @@ def to_files(self, *, folder: str = '.', name: str = None,
writer: A VTkWriters object. Default is binary which will write .vtp files.
config: Path to the config file in JSON format. Defaults to None.
validation: Boolean to indicate whether to validate the data before loading.
display_mode: Display mode for the model. Defaults to shaded.
model_display_mode: Display mode for the model. Defaults to shaded.
grid_display_mode: Display mode for the Grids. Defaults to shaded.
Returns:
A text string containing the path to the .zip file with VTK/VTP files.
"""
# update display mode
self.update_display_mode(display_mode)
scene = Scene()
actors = self.actors()
scene.add_actors(actors)

self.update_display_mode(model_display_mode)
self.sensor_grids.display_mode = grid_display_mode

# load data if provided
if config:
self.load_config(config, validation=validation)
self.load_config(config, scene=scene, validation=validation, legend=True)

# Name of the html file
file_name = name or 'model'
Expand Down

0 comments on commit 652b3f0

Please sign in to comment.