<commit_before>#!/usr/bin/env @PYTHON_EXECUTABLE@
"""
Description: Viewer and exporter for Siconos mechanics-IO HDF5 files based on VTK.
"""

# Lighter imports before command line parsing
from __future__ import print_function
import sys
import os
import json
import getopt
import math

# Exports from this module
__all__ = ['VView', 'VViewOptions', 'VExportOptions', 'VViewConfig']

if hasattr(math, 'inf'):
    infinity = math.inf
else:
    infinity = float('inf')

## Persistent configuration
class VViewConfig(dict):
    def __init__(self, d={'window_size': [600,600]}, filename=None):
        super(self.__class__, self).__init__(d)
        self.should_save_config = True
        if filename is not None:
            self.filename = filename
        else:
            self.filename = os.path.join(os.environ['HOME'], '.config',
                                         'siconos_vview.json')

    def load_configuration(self):
        if os.path.exists(self.filename):
            try:
                self.update(json.load(open(self.filename)))
                self.should_save_config = True
            except:
                self.should_save_config = False
                print("Warning: Error loading configuration `{}'".format(self.filename))

    def save_configuration(self, force=False):
        if not force and not self.should_save_config:
            return
        try:
            if not os.path.exists(os.path.join(os.environ['HOME'], '.config')):
                os.mkdir(os.path.join(os.environ['HOME'], '.config'))
            json.dump(self, open(self.filename,'w'))
        except:
            print("Error saving configuration `{}'".format(self.filename))


class VViewOptions(object):
    def __init__(self):
        self.min_time = None
        self.max_time = None
        self.cf_scale_factor = 1
        self.normalcone_ratio = 1
        self.time_scale_factor = 1
        self.advance_by_time = None
        self.frames_per_second = 25
        self.cf_disable = False
        self.initial_camera = [None] * 4
        self.visible_mode = 'all'

    ## Print usage information
    def usage(self, long=False):
        print(__doc__); print()
        print('Usage: {0} [OPTION]... <HDF5>'
              .format(os.path.split(sys.argv[0])[1]))
        print()
        if not long:
            print("""[--help] [tmin=<float value>] [tmax=<float value>]
    [--cf-scale=<float value>] [--no-cf]
    [--advance=<'fps' or float value>] [--fps=float value]
    [--camera=x,y,z] [--lookat=x,y,z] [--up=x,y,z] [--ortho=scale]
    """)
        else:
            print("""Options:
     --help
       display this message
     --version
       display version information
     --tmin= value
       set the time lower bound for visualization
     --tmax= value
       set the time upper bound for visualization
     --cf-scale= value  (default : 1.0 )
       rescale the arrow representing the contact forces by the value.
       the normal cone and the contact points are also rescaled
     --no-cf
       do not display contact forces
     --normalcone-ratio = value  (default : 1.0 )
       introduce a ratio between the representation of the contact forces arrows
       the normal cone and the contact points. useful when the contact forces are
       small with respect to the characteristic dimesion
     --advance= value or 'fps'
       automatically advance time during recording (default : don't advance)
     --fps= value
       frames per second of generated video (default 25)
     --camera=x,y,z
       initial position of the camera (default=above looking down)
     --lookat=x,y,z<commit_msg>[io] add some help comments<commit_after>#!/usr/bin/env @PYTHON_EXECUTABLE@
"""
Description: Viewer and exporter for Siconos mechanics-IO HDF5 files based on VTK.
"""

# Lighter imports before command line parsing
from __future__ import print_function
import sys
import os
import json
import getopt
import math

# Exports from this module
__all__ = ['VView', 'VViewOptions', 'VExportOptions', 'VViewConfig']

if hasattr(math, 'inf'):
    infinity = math.inf
else:
    infinity = float('inf')

## Persistent configuration
class VViewConfig(dict):
    def __init__(self, d={'window_size': [600,600]}, filename=None):
        super(self.__class__, self).__init__(d)
        self.should_save_config = True
        if filename is not None:
            self.filename = filename
        else:
            self.filename = os.path.join(os.environ['HOME'], '.config',
                                         'siconos_vview.json')

    def load_configuration(self):
        if os.path.exists(self.filename):
            try:
                self.update(json.load(open(self.filename)))
                self.should_save_config = True
            except:
                self.should_save_config = False
                print("Warning: Error loading configuration `{}'".format(self.filename))

    def save_configuration(self, force=False):
        if not force and not self.should_save_config:
            return
        try:
            if not os.path.exists(os.path.join(os.environ['HOME'], '.config')):
                os.mkdir(os.path.join(os.environ['HOME'], '.config'))
            json.dump(self, open(self.filename,'w'))
        except:
            print("Error saving configuration `{}'".format(self.filename))


class VViewOptions(object):
    def __init__(self):
        self.min_time = None
        self.max_time = None
        self.cf_scale_factor = 1
        self.normalcone_ratio = 1
        self.time_scale_factor = 1
        self.advance_by_time = None
        self.frames_per_second = 25
        self.cf_disable = False
        self.initial_camera = [None] * 4
        self.visible_mode = 'all'

    ## Print usage information
    def usage(self, long=False):
        print(__doc__); print()
        print('Usage: {0} [OPTION]... <HDF5>'
              .format(os.path.split(sys.argv[0])[1]))
        print()
        if not long:
            print("""[--help] [--tmin=<float value>] [--tmax=<float value>]
            [--cf-scale=<float value>] [--no-cf] [--normalcone-ratio = <float value>]
            [--advance=<'fps' or float value>] [--fps=float value]
            [--camera=x,y,z] [--lookat=x,y,z] [--up=x,y,z] [--ortho=scale]
            [--visible=all,avatars,contactors]
            """)
        else:
            print("""Options:
     --help
       display this message
     --version
       display version information
     --tmin= value
       set the time lower bound for visualization
     --tmax= value
       set the time upper bound for visualization
     --cf-scale= value  (default : 1.0 )
       rescale the arrow representing the contact forces by the value.
       the normal cone and the contact points are also rescaled
     --no-cf
       do not display contact forces
     --normalcone-ratio = value  (default : 1.0 )
       introduce a ratio between the representation of the contact forces arrows
       the normal cone and the contact points. useful when the contact forces are
       small with respect to the characteristic dimesion
     --advance= value or 'fps'
       automatically advance time during recording (default : don't advance)
     --fps= value
       frames per second of generated video (default 25)
     --camera=x,y,z
       initial position of the camera (default=above looking down)
     --lookat=x,y,z
{'fraction_non_alphanumeric': 0.1149783315276273, 'fraction_numerical': 0.006229685807150596, 'mean_word_length': 2.3101748095024655, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3350328', 'n_tokens_mistral': 2175, 'n_tokens_neox': 2108, 'n_words': 609}