├── .gitignore ├── CMakeLists.txt ├── COPYING ├── README.md ├── backends ├── blender2.59 │ ├── CMakeLists.txt │ └── dbus-server.py └── osg-gtk │ ├── CMakeLists.txt │ ├── python │ └── dbus-server.py │ └── src │ ├── osg_interpreter.hpp │ ├── osggtkdrawingarea.cpp │ ├── osggtkdrawingarea.h │ ├── osgviewerGTK.cpp │ ├── osgviewerGTK.hpp │ └── viewer.cpp ├── common └── cmake │ ├── FindDBUS.cmake │ ├── FindGLFW.cmake │ ├── FindGtkGl.cmake │ └── FindOMC.cmake ├── examples └── multibody │ ├── CMakeLists.txt │ └── src │ └── modelica │ ├── DoublePendulum.mo │ ├── Engine1b.mo │ ├── Internal.mo │ └── Pendulum.mo ├── lib ├── mod3d │ ├── CMakeLists.txt │ └── src │ │ └── modelica │ │ ├── Modelica3D 3.2.1 │ │ ├── package.mo │ │ └── required changes.txt │ │ └── package.mo ├── modbus │ ├── CMakeLists.txt │ └── src │ │ ├── c │ │ ├── modbus.c │ │ └── modbus.h │ │ └── modelica │ │ └── modbus │ │ └── package.mo ├── modcount │ ├── CMakeLists.txt │ └── src │ │ ├── c │ │ ├── modcount.c │ │ └── modcount.h │ │ └── modelica │ │ ├── Test.mo │ │ └── modcount │ │ └── package.mo └── proc3d │ ├── CMakeLists.txt │ └── src │ ├── animationContext.hpp │ ├── operations.hpp │ ├── proc3d.cpp │ └── proc3d.hpp └── test ├── CMakeLists.txt └── test.mos /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | build 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(modelica3d_dbus CXX C) 4 | option(USE_OMC "use openmodelica" OFF) 5 | option(OSG_BACKEND "build openscenegraph backed" ON) 6 | option(INSTALL_EXAMPLES "install examples" ON) 7 | option(BLENDER_BACKEND "build blender backed" ON) 8 | set(MODELICA_SERVICES_LIBRARY "ModelicaServices 3.2.1 modelica3d" CACHE STRING "Modelica Services library name") 9 | 10 | set(CPACK_PACKAGE_CONTACT "openmodelica@ida.liu.se") 11 | set(CPACK_SET_DESTDIR "ON") 12 | include(CPack) 13 | 14 | enable_testing() 15 | 16 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/common/cmake") 17 | 18 | if (USE_OMC) 19 | find_package(OMC REQUIRED) 20 | endif(USE_OMC) 21 | 22 | include_directories(${OMC_INCLUDES}) 23 | 24 | add_subdirectory(lib/modcount) 25 | add_subdirectory(lib/modbus) 26 | add_subdirectory(lib/mod3d) 27 | add_subdirectory(lib/proc3d) 28 | 29 | if(OSG_BACKEND) 30 | add_subdirectory(backends/osg-gtk) 31 | endif(OSG_BACKEND) 32 | 33 | if(BLENDER_BACKEND) 34 | add_subdirectory(backends/blender2.59) 35 | endif(BLENDER_BACKEND) 36 | 37 | if(INSTALL_EXAMPLES) 38 | add_subdirectory(examples/multibody) 39 | endif(INSTALL_EXAMPLES) 40 | 41 | add_subdirectory(test) 42 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Modelica3D # 2 | 3 | Modelica3D is a lightweight, platform independent 3D-visualisation library for Modelica. 4 | 5 | The original version of Modelica3D comes from https://mlcontrol.uebb.tu-berlin.de/redmine/projects/modelica3d-public. 6 | That project has not been updated in while and does not work in [OpenModelica](https://openmodelica.org). 7 | This fork works in the Modelica Standard Library 3.2.1 ([MSL 3.2.1](https://modelica.org)) and also no longer needs a patched standard library. 8 | -------------------------------------------------------------------------------- /backends/blender2.59/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES "dbus-server.py" 2 | DESTINATION "lib/omlibrary-modelica3d/blender-2.59") 3 | -------------------------------------------------------------------------------- /backends/blender2.59/dbus-server.py: -------------------------------------------------------------------------------- 1 | from dbus.mainloop.glib import DBusGMainLoop 2 | import dbus 3 | import dbus.service 4 | 5 | DBusGMainLoop(set_as_default=True) 6 | 7 | from gi.repository import GObject 8 | 9 | from bpy import ops, data, context 10 | from mathutils import Matrix 11 | 12 | from itertools import tee, product 13 | 14 | l = GObject.MainLoop() 15 | 16 | # Wrapper for dbus api decorator 17 | dec = dbus.service.method(dbus_interface='de.tuberlin.uebb.modelica3d.api', 18 | in_signature='a{sv}', 19 | out_signature='s') 20 | 21 | # decorate a function with optional typechecks 22 | def mod3D_api(**checks): 23 | def tc(f): 24 | print("Decorating %s with %s" % (str(f), checks)) 25 | 26 | def checked(s, **p) : 27 | #print("Got: %s %s" % (str(s), str(p))) 28 | for param in p: 29 | if param in checks: 30 | res,msg = checks[param](p[param]) 31 | if not res: 32 | return msg 33 | return f(s, **p) 34 | 35 | nf = lambda s, p={} : checked(s, **p) 36 | nf.__name__ = f.__name__ 37 | return dec(nf) 38 | 39 | return tc 40 | 41 | # Check for undefinded/defined references 42 | def undefined_object(ref) : 43 | return (not ref in data.objects, "%s is already in use." % str(ref)) 44 | 45 | def defined_object(ref) : 46 | return (ref in data.objects, "%s undefined" % str(ref)) 47 | 48 | def undefined_material(ref) : 49 | return (not ref in data.materials, "%s is already in use." % str(ref)) 50 | 51 | def defined_material(ref) : 52 | return (ref in data.materials, "%s undefined" % str(ref)) 53 | 54 | # Check for positive value 55 | def positive(s): 56 | return (s <= 0.0, "expected positive value") 57 | 58 | def positive_int(i): 59 | return (isinstance(i, int) and i >= 0, "expected positive int") 60 | 61 | def not_zero(x): 62 | return (i != 0, "parameter may not be zero") 63 | 64 | class Modelica3DAPI(dbus.service.Object): 65 | 66 | @mod3D_api() 67 | def stop(self): 68 | l.quit() 69 | return "stopped" 70 | 71 | @mod3D_api(reference = undefined_object, length = not_zero) 72 | def make_box(self, reference=-1, length=1, width=1, height=1): 73 | ops.mesh.primitive_cube_add() 74 | context.active_object.name = reference 75 | size = (length, width, height) 76 | ops.transform.resize(size) 77 | return reference 78 | 79 | @mod3D_api(reference = defined_object, frame = positive_int) 80 | def move_to(self, reference, x=None, y=None, z=None, frame=1, immediate=False): 81 | o = data.objects[reference] 82 | context.scene.frame_set(frame=frame) 83 | if immediate: 84 | o.keyframe_insert('location', frame=frame - 1) 85 | 86 | if (x != None): 87 | o.location.x = x 88 | if (y != None): 89 | o.location.y = y 90 | if (z != None): 91 | o.location.z = z 92 | 93 | o.keyframe_insert('location', frame=frame) 94 | 95 | return reference 96 | 97 | @mod3D_api(reference = defined_object, frame = positive_int) 98 | def scale(self, reference, x=None, y=None, z=None, frame=1, immediate=False): 99 | o = data.objects[reference] 100 | context.scene.frame_set(frame=frame) 101 | if immediate: 102 | o.keyframe_insert('scale', frame=frame - 1) 103 | 104 | if (x != None): 105 | o.scale.x = x 106 | if (y != None): 107 | o.scale.y = y 108 | if (z != None): 109 | o.scale.z = z 110 | 111 | o.keyframe_insert('scale', frame=frame) 112 | 113 | return reference 114 | 115 | @mod3D_api(reference = defined_material, frame = positive_int) 116 | def set_material_property(self, reference, prop, value, immediate=True, frame=1): 117 | context.scene.frame_set(frame=frame) 118 | o = data.materials[reference] 119 | 120 | if immediate: 121 | o.keyframe_insert(prop, frame=frame - 1) 122 | 123 | setattr(o, prop, value) 124 | 125 | o.keyframe_insert(prop, frame=frame) 126 | 127 | return reference 128 | 129 | @mod3D_api(reference = undefined_object) 130 | def make_cone(self, reference, x=0.0, y=0.0, z=1.0, diameter=1.0, height=1.0): 131 | ops.mesh.primitive_cone_add(radius=diameter / 2.0, depth=height) 132 | context.active_object.name = reference 133 | return reference 134 | 135 | @mod3D_api(reference = undefined_object) 136 | def make_sphere(self, reference, size): 137 | ops.mesh.primitive_uv_sphere_add(size=size) 138 | context.active_object.name = reference 139 | return reference 140 | 141 | @mod3D_api(reference = undefined_object) 142 | def make_cylinder(self, reference, x=0.0, y=0.0, z=1.0, diameter=1.0, height=1.0): 143 | ops.mesh.primitive_cylinder_add(radius=diameter / 2.0, depth=height) 144 | context.active_object.name = reference 145 | return reference 146 | 147 | @mod3D_api() 148 | def load_scene(self, filepath): 149 | with data.libraries.load(filepath) as (src, _): 150 | try: 151 | objlist = [{'name':obj} for obj in src.objects] 152 | except UnicodeDecodeError as detail: 153 | print(detail) 154 | 155 | ops.wm.link_append(directory=filepath + '/Object/', link=False, autoselect=True, files=objlist) 156 | return filepath 157 | 158 | @mod3D_api(reference = defined_object, frame = positive_int) 159 | def rotate(self, reference, R_1_1, R_1_2, R_1_3, R_2_1,R_2_2, R_2_3, R_3_1, R_3_2, R_3_3, frame, immediate=False): 160 | if None in [R_1_1, R_1_2, R_1_3, R_2_1,R_2_2, R_2_3, R_3_1, R_3_2, R_3_3] : return "Argument error." 161 | o = data.objects[reference] 162 | context.scene.objects.active=o 163 | if immediate: 164 | o.keyframe_insert('rotation_euler', frame=frame - 1) 165 | 166 | m = Matrix(([R_1_1,R_1_2, R_1_3], 167 | [R_2_1,R_2_2, R_2_3], 168 | [R_3_1,R_3_2, R_3_3])) 169 | e = m.to_euler() 170 | ops.transform.rotate(value=(e[0],), axis=(1.0,0,0)) 171 | ops.transform.rotate(value=(e[1],), axis=(0,1.0,0)) 172 | ops.transform.rotate(value=(e[2],), axis=(0,0,1.0)) 173 | o.keyframe_insert('rotation_euler', frame=frame) 174 | return reference 175 | 176 | if __name__ == '__main__': 177 | # delete default cube 178 | if 'Cube' in data.objects: 179 | context.scene.objects.active = data.objects['Cube'] 180 | ops.object.delete() 181 | 182 | session_bus = dbus.SessionBus() 183 | name = dbus.service.BusName("de.tuberlin.uebb.modelica3d.server", session_bus) 184 | api = Modelica3DAPI(session_bus, "/de/tuberlin/uebb/modelica3d/server") 185 | l.run() 186 | -------------------------------------------------------------------------------- /backends/osg-gtk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(GtkGl REQUIRED) 2 | find_package(OpenSceneGraph REQUIRED osgGA osgText osgViewer osgDB) 3 | 4 | if(MINGW) 5 | add_definitions(-std=c++0x -U__STRICT_ANSI__ -mms-bitfields) 6 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 7 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.3") 8 | message("clang <3.3 detected; changing to default c++ instead since clang 3.0~3.2 are not good enough for the used headers") 9 | set(CMAKE_CXX_COMPILER c++) 10 | endif() 11 | add_definitions(-std=c++0x) 12 | else () 13 | add_definitions(-std=c++0x) 14 | endif(MINGW) 15 | 16 | #requires osg, gtk and proc3d 17 | include_directories(${Boost_INCLUDE_DIR} ${GTK_INCLUDE_DIRS} "${CMAKE_SOURCE_DIR}/lib/proc3d/src/" ${GTKGL_INCLUDE_DIRS} ${OPENSCENEGRAPH_INCLUDE_DIRS}) 18 | link_directories(${GTK_LIBRARY_DIRS} ${GTKGL_LIBRARY_DIRS}) 19 | 20 | set(osg-gtk_src "${CMAKE_SOURCE_DIR}/backends/osg-gtk/src/") 21 | 22 | add_library(m3d-osg-gtk SHARED 23 | "${osg-gtk_src}/osg_interpreter.hpp" 24 | "${osg-gtk_src}/osgviewerGTK.hpp" 25 | "${osg-gtk_src}/osgviewerGTK.cpp" 26 | "${osg-gtk_src}/osggtkdrawingarea.h" 27 | "${osg-gtk_src}/osggtkdrawingarea.cpp" 28 | ) 29 | add_dependencies(m3d-osg-gtk proc3d) 30 | 31 | target_link_libraries(m3d-osg-gtk ${OPENSCENEGRAPH_LIBRARIES} ${GTK_LIBRARIES} ${GTKGL_LIBRARIES} proc3d) 32 | 33 | add_executable(viewer "${osg-gtk_src}/viewer.cpp") 34 | target_link_libraries(viewer m3d-osg-gtk) 35 | 36 | install(TARGETS m3d-osg-gtk 37 | RUNTIME DESTINATION bin 38 | LIBRARY DESTINATION lib 39 | ARCHIVE DESTINATION lib 40 | ) 41 | 42 | install(FILES "python/dbus-server.py" 43 | DESTINATION "lib/omlibrary-modelica3d/osg-gtk") 44 | -------------------------------------------------------------------------------- /backends/osg-gtk/python/dbus-server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | import platform 5 | from ctypes import * 6 | 7 | # OPENMODELICA :: This is openmodelica based path which provides the dbus-python bindings binaries. 8 | if sys.platform == 'win32': 9 | omhome = os.environ['OPENMODELICAHOME'] 10 | sys.path.append(os.path.join(omhome, 'lib', 'omlibrary-modelica3d', 'osg-gtk', 'dbus-python')) 11 | 12 | # load DLL or shared object 13 | if (platform.system() == 'Linux'): 14 | viewer = CDLL("libm3d-osg-gtk.so") # GTK/OSG backend 15 | proc3d = CDLL("libproc3d.so") # procedural 3d 16 | elif (platform.system() == 'Windows'): 17 | viewer = CDLL("libm3d-osg-gtk.dll") # GTK/OSG backend 18 | proc3d = CDLL("libproc3d.dll") # procedural 3d 19 | elif (platform.system() == 'Darwin'): 20 | try: 21 | omhome = os.environ['OPENMODELICAHOME'] 22 | print "Using OPENMODELICA to find backends:",omhome 23 | except: 24 | try: 25 | omhome = os.path.abspath(__file__).split('/lib')[0] 26 | print "Using script location to find backends:",omhome 27 | except: 28 | print "Could not determine OPENMODELICAHOME; needed on OSX to find libproc3d.dylib" 29 | sys.exit(1) 30 | path = os.path.join(omhome, 'lib') 31 | viewer = CDLL(os.path.join(path,"libm3d-osg-gtk.dylib")) # GTK/OSG backend 32 | proc3d = CDLL(os.path.join(path,"libproc3d.dylib")) # procedural 3d 33 | 34 | viewer.osg_gtk_alloc_context.restype = c_void_p 35 | 36 | from dbus.mainloop.glib import DBusGMainLoop 37 | import dbus 38 | import dbus.service 39 | 40 | DBusGMainLoop(set_as_default=True) 41 | 42 | if sys.platform == 'win32': 43 | import gobject 44 | l = gobject.MainLoop() 45 | else: 46 | from gi.repository import GObject 47 | l = GObject.MainLoop() 48 | 49 | # Wrapper for dbus api decorator 50 | dec = dbus.service.method(dbus_interface='de.tuberlin.uebb.modelica3d.api', 51 | in_signature='a{sv}', 52 | out_signature='s') 53 | 54 | # decorate a function with optional typechecks 55 | def mod3D_api(**checks): 56 | def tc(f): 57 | #print("Decorating %s with %s" % (str(f), checks)) 58 | 59 | def checked(s, **p) : 60 | #print("Got: %s %s" % (str(s), str(p))) 61 | for param in p: 62 | if param in checks: 63 | res,msg = checks[param](p[param]) 64 | if not res: 65 | print msg 66 | return msg 67 | return f(s, **p) 68 | 69 | nf = lambda s, p={} : checked(s, **p) 70 | nf.__name__ = f.__name__ 71 | return dec(nf) 72 | 73 | return tc 74 | 75 | # Check for undefinded/defined references 76 | def undefined_object(ref) : 77 | return (True, "%s is already in use." % str(ref)) 78 | 79 | def defined_object(ref) : 80 | return (True, "%s undefined" % str(ref)) 81 | 82 | def undefined_material(ref) : 83 | return (True, "%s is already in use." % str(ref)) 84 | 85 | def defined_material(ref) : 86 | return (True, "%s undefined" % str(ref)) 87 | 88 | # Check for positive value 89 | def positive(s): 90 | return (s <= 0.0, "expected positive value") 91 | 92 | def positive_int(i): 93 | return (isinstance(i,int) and i >= 0, "expected positive int") 94 | 95 | def not_zero(x): 96 | return (x != 0, "parameter may not be zero") 97 | 98 | def existing_file(x): 99 | return (os.path.isfile(x), "File %s does not exist!" % x) 100 | 101 | class Modelica3DAPI(dbus.service.Object): 102 | 103 | @mod3D_api() 104 | def stop(self): 105 | # Quit the dbus server 106 | l.quit() 107 | return "stopped" 108 | 109 | @mod3D_api(reference = undefined_object, length = not_zero) 110 | def make_box(self, reference, length=1, width=1, height=1, tx=0.0, ty=0.0, tz=1.0): 111 | self.omg.proc3d_create_box(self.ctxt, c_char_p(reference), 112 | c_double(tx), c_double(ty), c_double(tz), 113 | c_double(width), c_double(length), c_double(height)) 114 | return reference 115 | 116 | @mod3D_api(reference = undefined_object, height = not_zero, diameter = not_zero) 117 | def make_cone(self, reference, x=0.0, y=0.0, z=1.0, diameter=1, height=5): 118 | self.omg.proc3d_create_cone(self.ctxt, c_char_p(reference), c_double(x), c_double(y), c_double(z), c_double(height), c_double(diameter / 2.0)); 119 | return reference 120 | 121 | @mod3D_api(reference = undefined_object, size = not_zero) 122 | def make_sphere(self, reference, size=1): 123 | self.omg.proc3d_create_sphere(self.ctxt, c_char_p(reference), c_double(size / 2.0)); 124 | return reference 125 | 126 | @mod3D_api(reference = undefined_object, height = not_zero, diameter = not_zero) 127 | def make_cylinder(self, reference, x=0.0, y=0.0, z=1.0, diameter=1, height = 10): 128 | self.omg.proc3d_create_cylinder(self.ctxt, c_char_p(reference), c_double(x), c_double(y), c_double(z), c_double(height), c_double(diameter / 2.0)) 129 | return reference 130 | 131 | @mod3D_api(reference = defined_object) 132 | def move_to(self, reference, x=0.0, y=0.0, z=0.0, t=0.0, immediate=False): 133 | self.omg.proc3d_set_translation(self.ctxt, c_char_p(reference), c_double(x), c_double(y), c_double(z), c_double(t)); 134 | return reference 135 | 136 | @mod3D_api(reference = defined_object) 137 | def scale(self, reference, x=0.0, y=0.0, z=0.0, t=0.0, immediate=False): 138 | self.omg.proc3d_set_scale(self.ctxt, c_char_p(reference), c_double(x), c_double(y), c_double(z), c_double(t)) 139 | return reference 140 | 141 | @mod3D_api(reference = undefined_material) 142 | def make_material(self, reference): 143 | self.omg.proc3d_create_material(self.ctxt, c_char_p(reference)) 144 | return reference 145 | 146 | @mod3D_api(reference = defined_object, material=defined_material) 147 | def apply_material(self, reference, material): 148 | self.omg.proc3d_apply_material(self.ctxt, c_char_p(reference), c_char_p(material)) 149 | return reference 150 | 151 | @mod3D_api(reference = defined_material) 152 | def set_material_property(self, reference, prop, value, immediate=True, t=0.0): 153 | self.omg.proc3d_set_material_property(self.ctxt, c_char_p(reference), c_double(value), c_char_p(prop), c_double(t)) 154 | return reference 155 | 156 | @mod3D_api(reference = defined_material) 157 | def set_ambient_color(self, reference, r=0.5, g=0.5, b=0.5, a=0, immediate=True, t=0.0): 158 | self.omg.proc3d_set_ambient_color(self.ctxt, c_char_p(reference), c_double(r), c_double(g) , c_double(b) , c_double(a), c_double(t)) 159 | return reference 160 | 161 | @mod3D_api(reference = defined_material) 162 | def set_diffuse_color(self, reference, r=0.5, g=0.5, b=0.5, a=0, immediate=True, t=0.0): 163 | self.omg.proc3d_set_diffuse_color(self.ctxt, c_char_p(reference), c_double(r), c_double(g) , c_double(b) , c_double(a), c_double(t)) 164 | return reference 165 | 166 | @mod3D_api(reference = defined_material) 167 | def set_specular_color(self, reference, r=0.5, g=0.5, b=0.5, a=0, immediate=True, t=0.0): 168 | self.omg.proc3d_set_specular_color(self.ctxt, c_char_p(reference), c_double(r), c_double(g) , c_double(b) , c_double(a), c_double(t)) 169 | return reference 170 | 171 | @mod3D_api(reference = defined_object) 172 | def rotate(self, reference, 173 | R_1_1, R_1_2, R_1_3, 174 | R_2_1, R_2_2, R_2_3, 175 | R_3_1, R_3_2, R_3_3, 176 | t=0.0): 177 | self.omg.proc3d_set_rotation_matrix(self.ctxt, c_char_p(reference), 178 | c_double(R_1_1), c_double(R_1_2), c_double(R_1_3), 179 | c_double(R_2_1), c_double(R_2_2), c_double(R_2_3), 180 | c_double(R_3_1), c_double(R_3_2), c_double(R_3_3), 181 | c_double(t)) 182 | return reference 183 | 184 | @mod3D_api(reference = undefined_object, fileName = existing_file) 185 | def loadFromFile(self, reference, fileName, tx=0.0, ty=0.0, tz=1.0): 186 | self.omg.proc3d_load_object(self.ctxt, c_char_p(reference), c_char_p(fileName), 187 | c_double(tx), c_double(ty), c_double(tz)) 188 | return reference 189 | 190 | 191 | if __name__ == '__main__': 192 | session_bus = dbus.SessionBus() 193 | name = dbus.service.BusName("de.tuberlin.uebb.modelica3d.server", session_bus) 194 | api = Modelica3DAPI(session_bus, "/de/tuberlin/uebb/modelica3d/server") 195 | 196 | ctxt = c_void_p(viewer.osg_gtk_alloc_context()) 197 | api.omg = proc3d 198 | api.ctxt = ctxt 199 | 200 | print("Running dbus-server...") 201 | l.run() 202 | print("dbus server finished.") 203 | 204 | proc3d.proc3d_send_signal(ctxt, 1) # run viewer 205 | viewer.osg_gtk_free_context(ctxt) 206 | -------------------------------------------------------------------------------- /backends/osg-gtk/src/osg_interpreter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include // LoadNodeFile-Operator 33 | #include // LoadNodeFile-Operator 34 | #include 35 | #include 36 | 37 | #include "operations.hpp" 38 | 39 | using namespace proc3d; 40 | using namespace osg; 41 | 42 | typedef std::map> t_node_cache; 43 | typedef std::map> t_material_cache; 44 | 45 | struct proc3d_osg_interpreter : boost::static_visitor<> { 46 | private: 47 | const ref_ptr root; 48 | public: 49 | t_node_cache& node_cache; 50 | t_material_cache& material_cache; 51 | 52 | proc3d_osg_interpreter(const ref_ptr r, t_node_cache& c, t_material_cache& m) : 53 | root(r), node_cache(c), material_cache(m) {} 54 | 55 | void operator()(const CreateGroup& cmd) const { 56 | 57 | } 58 | 59 | void operator()(const AddToGroup& cmd) const { 60 | 61 | } 62 | 63 | void operator()(const CreateMaterial& cmd) const { 64 | ref_ptr mat = new Material(); 65 | mat->setName(cmd.name); 66 | material_cache[cmd.name] = mat; 67 | } 68 | 69 | void operator()(const ApplyMaterial& cmd) const { 70 | 71 | // do not apply material to file objects (where target name begins with "file") 72 | // a better idea is needed -> are the colors specified in modelica to be ignored or not? 73 | const std::string FILE("file"); 74 | if (cmd.name.compare(0, FILE.length(), FILE) == 0) return; 75 | 76 | if (node_cache.find(cmd.name) == node_cache.end()) { 77 | std::cout << "Inconsistent naming. Did not find " << cmd.name << std::endl; 78 | return; 79 | } 80 | 81 | if (material_cache.find(cmd.target) == material_cache.end()) { 82 | std::cout << "Inconsistent naming. Did not find material: " << cmd.target << std::endl; 83 | return; 84 | } 85 | 86 | std::cout << "Apply material " << cmd.target << " on " << cmd.name << std::endl; 87 | 88 | const ref_ptr mat = material_cache[cmd.target]; 89 | 90 | ref_ptr stateSet = node_cache[cmd.name] -> getChild(0) -> getOrCreateStateSet(); 91 | stateSet->setAttribute(mat.get()); 92 | } 93 | 94 | void operator()(const CreateSphere& cmd) const { 95 | const ref_ptr shape = 96 | new ShapeDrawable(new Sphere(Vec3(cmd.radius,0,0), cmd.radius)); 97 | const ref_ptr geode = new Geode(); 98 | geode->addDrawable(shape); 99 | 100 | const ref_ptr trans = 101 | new PositionAttitudeTransform(); 102 | trans->addChild(geode); 103 | trans->setName(cmd.name); 104 | 105 | node_cache[cmd.name] = trans; 106 | root->addChild(trans); 107 | } 108 | 109 | void operator()(const CreateBox& cmd) const { 110 | osg::Vec3 target = osg::Vec3(cmd.at[0], cmd.at[1], cmd.at[2]); 111 | target.normalize(); 112 | target *= cmd.height; 113 | const Vec3 center = target / 2.0; 114 | 115 | //Rotate to target 116 | const Vec3 z = osg::Vec3(0,0,1); 117 | Quat q; q.makeRotate(z, target); 118 | 119 | const ref_ptr shape = new Box(center, cmd.width, cmd.length, cmd.height); 120 | const ref_ptr draw = new ShapeDrawable(shape); 121 | 122 | const ref_ptr geode = new Geode(); 123 | geode->addDrawable(draw); 124 | 125 | const ref_ptr trans = 126 | new PositionAttitudeTransform(); 127 | trans->addChild(geode); 128 | trans->setName(cmd.name); 129 | 130 | shape->setRotation(q); 131 | 132 | node_cache[cmd.name] = trans; 133 | root->addChild(trans); 134 | } 135 | 136 | void operator()(const CreateCylinder& cmd) const { 137 | osg::Vec3 target = osg::Vec3(cmd.at[0], cmd.at[1], cmd.at[2]); 138 | target.normalize(); 139 | target *= cmd.height; 140 | const Vec3 center = target / 2.0; 141 | 142 | //Rotate to target 143 | const Vec3 z = osg::Vec3(0,0,1); 144 | Quat q; q.makeRotate(z, target); 145 | 146 | const ref_ptr shape = new Cylinder(center, cmd.radius, cmd.height); 147 | const ref_ptr draw = new ShapeDrawable(shape); 148 | 149 | const ref_ptr geode = new Geode(); 150 | geode->addDrawable(draw); 151 | 152 | const ref_ptr trans = 153 | new PositionAttitudeTransform(); 154 | trans->addChild(geode); 155 | trans->setName(cmd.name); 156 | 157 | shape->setRotation(q); 158 | 159 | node_cache[cmd.name] = trans; 160 | root->addChild(trans); 161 | } 162 | 163 | void operator()(const CreateCone& cmd) const { 164 | osg::Vec3 target = osg::Vec3(cmd.at[0], cmd.at[1], cmd.at[2]); 165 | target.normalize(); 166 | target *= cmd.height; 167 | 168 | //Rotate to target 169 | const Vec3 z = osg::Vec3(0,0,1); 170 | Quat q; q.makeRotate(z, target); 171 | 172 | const ref_ptr shape = new Cone(Vec3d(0,0,0), cmd.radius, cmd.height); 173 | const ref_ptr draw = new ShapeDrawable(shape); 174 | 175 | const ref_ptr geode = new Geode(); 176 | geode->addDrawable(draw); 177 | 178 | const ref_ptr trans = 179 | new PositionAttitudeTransform(); 180 | trans->addChild(geode); 181 | trans->setName(cmd.name); 182 | 183 | shape->setRotation(q); 184 | 185 | node_cache[cmd.name] = trans; 186 | root->addChild(trans); 187 | } 188 | 189 | void operator()(const CreatePlane& cmd) const { 190 | const ref_ptr shape = new Box(Vec3(0,0,0), cmd.width, cmd.length, 0.05); 191 | const ref_ptr draw = new ShapeDrawable(shape); 192 | 193 | const ref_ptr geode = new Geode(); 194 | geode->addDrawable(draw); 195 | 196 | const ref_ptr trans = 197 | new PositionAttitudeTransform(); 198 | trans->addChild(geode); 199 | trans->setName(cmd.name); 200 | 201 | node_cache[cmd.name] = trans; 202 | root->addChild(trans); 203 | } 204 | 205 | void operator()(const Move& cmd) const { 206 | if (node_cache.find(cmd.name) == node_cache.end()) { 207 | std::cout << "Inconsistent naming. Did not find " << cmd.name << std::endl; 208 | return; 209 | } 210 | 211 | node_cache[cmd.name] -> setPosition(Vec3d(cmd.x, cmd.y, cmd.z)); 212 | } 213 | 214 | void operator()(const Scale& cmd) const { 215 | if (node_cache.find(cmd.name) == node_cache.end()) { 216 | std::cout << "Inconsistent naming. Did not find " << cmd.name << std::endl; 217 | return; 218 | } 219 | 220 | node_cache[cmd.name] -> setScale(Vec3d(cmd.x, cmd.y, cmd.z)); 221 | } 222 | 223 | void operator()(const RotateEuler& cmd) const { 224 | if (node_cache.find(cmd.name) == node_cache.end()) { 225 | std::cout << "Inconsistent naming. Did not find " << cmd.name << std::endl; 226 | return; 227 | } 228 | 229 | Quat q(cmd.x, osg::Vec3(1,0,0), cmd.y, osg::Vec3(0,1,0), cmd.z, osg::Vec3(0,0,1)); 230 | node_cache[cmd.name] -> setAttitude(q); 231 | } 232 | 233 | void operator()(const RotateMatrix& cmd) const { 234 | if (node_cache.find(cmd.name) == node_cache.end()) { 235 | std::cout << "Inconsistent naming. Did not find " << cmd.name << std::endl; 236 | return; 237 | } 238 | 239 | Quat q; 240 | const auto& m = cmd.m; 241 | 242 | q.set(osg::Matrixd(m(0,0), m(0,1), m(0,2), 0.0, 243 | m(1,0), m(1,1), m(1,2), 0.0, 244 | m(2,0), m(2,1), m(2,2), 0.0, 245 | 0.0, 0.0, 0.0, 1.0)); 246 | 247 | node_cache[cmd.name] -> setAttitude(q); 248 | } 249 | 250 | void operator()(const SetMaterialProperty& cmd) const { 251 | if (material_cache.find(cmd.name) == material_cache.end()) { 252 | std::cout << "Inconsistent naming. Did not find material: " << cmd.name << std::endl; 253 | return; 254 | } 255 | //no properties defined yet ... 256 | } 257 | 258 | static inline Vec4d vec4_from_array(const boost::array& arr) { 259 | return Vec4d(arr[0],arr[1],arr[2],arr[3]); 260 | } 261 | 262 | void operator()(const SetAmbientColor& cmd) const { 263 | if (material_cache.find(cmd.name) == material_cache.end()) { 264 | std::cout << "Inconsistent naming. Did not find material: " << cmd.name << std::endl; 265 | return; 266 | } 267 | 268 | std::cout << "Setting ambient color on " << cmd.name << " at t= " << cmd.time << std::endl; 269 | material_cache[cmd.name]->setAmbient(Material::FRONT, vec4_from_array(cmd.color)); 270 | } 271 | 272 | void operator()(const SetDiffuseColor& cmd) const { 273 | if (material_cache.find(cmd.name) == material_cache.end()) { 274 | std::cout << "Inconsistent naming. Did not find material: " << cmd.name << std::endl; 275 | return; 276 | } 277 | 278 | material_cache[cmd.name]->setDiffuse(Material::FRONT, vec4_from_array(cmd.color)); 279 | } 280 | 281 | void operator()(const SetSpecularColor& cmd) const { 282 | if (material_cache.find(cmd.name) == material_cache.end()) { 283 | std::cout << "Inconsistent naming. Did not find material: " << cmd.name << std::endl; 284 | return; 285 | } 286 | 287 | material_cache[cmd.name]->setSpecular(Material::FRONT, vec4_from_array(cmd.color)); 288 | } 289 | 290 | // LoadObject 291 | void operator()(const LoadObject& cmd) const { 292 | ref_ptr node = osgDB::readNodeFile(cmd.fileName); // fileName better be absolute 293 | if(!node.valid()){ 294 | std::cout << "Cannot open File: " << cmd.fileName << std::endl; 295 | return; 296 | } 297 | 298 | // Shader Quellcode 299 | std::string vs = 300 | "varying vec3 vNormal;" 301 | "varying vec3 ecPosition3;" 302 | "void main(void)" 303 | "{" 304 | " gl_Position = ftransform();" 305 | " vNormal = gl_NormalMatrix * gl_Normal;" 306 | " vec4 ecPosition4 = gl_ModelViewMatrix * gl_Vertex;" 307 | " ecPosition3 =(vec3(ecPosition4)) / ecPosition4.w;" 308 | "}"; 309 | 310 | std::string fs = 311 | "varying vec3 vNormal;" 312 | "varying vec3 ecPosition3;" 313 | "void main(void)" 314 | "{" 315 | " vec3 L = normalize(ecPosition3);" 316 | " vec3 N = normalize(vNormal);" 317 | " float D = abs(dot(N,L));" 318 | " vec3 ambient = gl_FrontMaterial.ambient * D;" 319 | " vec3 diffuse = gl_FrontMaterial.diffuse * D;" 320 | " vec3 color = diffuse;" 321 | " gl_FragColor = vec4(color,1.0);" 322 | "}"; 323 | 324 | // OSG-Shader 325 | osg::Shader* vShader = new osg::Shader(osg::Shader::VERTEX,vs); 326 | osg::Shader* fShader = new osg::Shader(osg::Shader::FRAGMENT,fs); 327 | 328 | // Shader-Program-Objekt 329 | osg::Program* sProgram = new osg::Program; 330 | sProgram->addShader(vShader); 331 | sProgram->addShader(fShader); 332 | 333 | ref_ptr ss = node->getOrCreateStateSet(); 334 | ss->setAttributeAndModes( sProgram, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); 335 | 336 | const ref_ptr trans = new PositionAttitudeTransform(); 337 | trans->addChild(node); 338 | trans->setName(cmd.name); 339 | 340 | node_cache[cmd.name] = trans; 341 | root->addChild(trans); 342 | } 343 | }; 344 | 345 | 346 | -------------------------------------------------------------------------------- /backends/osg-gtk/src/osggtkdrawingarea.cpp: -------------------------------------------------------------------------------- 1 | #include "osggtkdrawingarea.h" 2 | 3 | OSGGTKDrawingArea::OSGGTKDrawingArea(): 4 | _widget (gtk_drawing_area_new()), 5 | _glconfig (0), 6 | _context (0), 7 | _drawable (0), 8 | _state (0), 9 | _queue (*getEventQueue()) { 10 | setCameraManipulator(new osgGA::TrackballManipulator()); 11 | setLightingMode(osg::View::HEADLIGHT); 12 | } 13 | 14 | OSGGTKDrawingArea::~OSGGTKDrawingArea() { 15 | } 16 | 17 | bool OSGGTKDrawingArea::createWidget(int width, int height) { 18 | _glconfig = gdk_gl_config_new_by_mode(static_cast( 19 | GDK_GL_MODE_RGBA | 20 | GDK_GL_MODE_DEPTH | 21 | GDK_GL_MODE_DOUBLE 22 | )); 23 | 24 | if(not _glconfig) { 25 | osg::notify(osg::FATAL) << "Fail!" << std::endl; 26 | 27 | return false; 28 | } 29 | 30 | gtk_widget_set_size_request(_widget, width, height); 31 | 32 | gtk_widget_set_gl_capability( 33 | _widget, 34 | _glconfig, 35 | 0, 36 | true, 37 | GDK_GL_RGBA_TYPE 38 | ); 39 | 40 | gtk_widget_add_events( 41 | _widget, 42 | GDK_BUTTON1_MOTION_MASK | 43 | GDK_BUTTON2_MOTION_MASK | 44 | GDK_BUTTON3_MOTION_MASK | 45 | GDK_POINTER_MOTION_MASK | 46 | GDK_BUTTON_PRESS_MASK | 47 | GDK_BUTTON_RELEASE_MASK | 48 | GDK_KEY_PRESS_MASK | 49 | GDK_KEY_RELEASE_MASK | 50 | GDK_VISIBILITY_NOTIFY_MASK 51 | ); 52 | 53 | // We do this so that we don't have to suck up ALL the input to the 54 | // window, but instead just when the drawing area is focused. 55 | g_object_set(_widget, "can-focus", true, NULL); 56 | 57 | _connect("realize", G_CALLBACK(&OSGGTKDrawingArea::_srealize)); 58 | _connect("unrealize", G_CALLBACK(&OSGGTKDrawingArea::_sunrealize)); 59 | _connect("expose_event", G_CALLBACK(&OSGGTKDrawingArea::_sexpose_event)); 60 | _connect("configure_event", G_CALLBACK(&OSGGTKDrawingArea::_sconfigure_event)); 61 | _connect("motion_notify_event", G_CALLBACK(&OSGGTKDrawingArea::_smotion_notify_event)); 62 | _connect("button_press_event", G_CALLBACK(&OSGGTKDrawingArea::_sbutton_press_event)); 63 | _connect("button_release_event", G_CALLBACK(&OSGGTKDrawingArea::_sbutton_press_event)); 64 | _connect("key_press_event", G_CALLBACK(&OSGGTKDrawingArea::_skey_press_event)); 65 | 66 | _gw = setUpViewerAsEmbeddedInWindow(0, 0, width, height); 67 | 68 | return true; 69 | } 70 | 71 | void OSGGTKDrawingArea::_realize(GtkWidget* widget) { 72 | _context = gtk_widget_get_gl_context(widget); 73 | _drawable = gtk_widget_get_gl_drawable(widget); 74 | 75 | gtkRealize(); 76 | } 77 | 78 | void OSGGTKDrawingArea::_unrealize(GtkWidget* widget) { 79 | gtkUnrealize(); 80 | } 81 | 82 | bool OSGGTKDrawingArea::_expose_event(GtkWidget* widget, GdkEventExpose* event) { 83 | if(not gtkGLBegin()) return false; 84 | 85 | frame(); 86 | 87 | gtkGLSwap(); 88 | gtkGLEnd(); 89 | 90 | return gtkExpose(); 91 | } 92 | 93 | bool OSGGTKDrawingArea::_configure_event(GtkWidget* widget, GdkEventConfigure* event) { 94 | gtkGLBegin(); 95 | 96 | _queue.windowResize(0, 0, event->width, event->height); 97 | 98 | _gw->resized(0, 0, event->width, event->height); 99 | 100 | gtkGLEnd(); 101 | 102 | return gtkConfigure(event->width, event->height); 103 | } 104 | 105 | bool OSGGTKDrawingArea::_motion_notify_event(GtkWidget* widget, GdkEventMotion* event) { 106 | _state = event->state; 107 | 108 | _queue.mouseMotion(event->x, event->y); 109 | 110 | return gtkMotionNotify(event->x, event->y); 111 | } 112 | 113 | bool OSGGTKDrawingArea::_button_press_event(GtkWidget* widget, GdkEventButton* event) { 114 | _state = event->state; 115 | 116 | if(event->type == GDK_BUTTON_PRESS) { 117 | if(event->button == 1) gtk_widget_grab_focus(_widget); 118 | 119 | _queue.mouseButtonPress(event->x, event->y, event->button); 120 | 121 | return gtkButtonPress(event->x, event->y, event->button); 122 | } 123 | 124 | else if(event->type == GDK_BUTTON_RELEASE) { 125 | _queue.mouseButtonRelease(event->x, event->y, event->button); 126 | 127 | return gtkButtonRelease(event->x, event->y, event->button); 128 | } 129 | 130 | else return false; 131 | } 132 | 133 | bool OSGGTKDrawingArea::_key_press_event(GtkWidget* widget, GdkEventKey* event) { 134 | _state = event->state; 135 | 136 | if(event->type == GDK_KEY_PRESS) { 137 | _queue.keyPress(event->keyval); 138 | 139 | return gtkKeyPress(event->keyval); 140 | } 141 | 142 | else if(event->type == GDK_KEY_RELEASE) { 143 | _queue.keyRelease(event->keyval); 144 | 145 | return gtkKeyRelease(event->keyval); 146 | } 147 | 148 | else return false; 149 | } 150 | -------------------------------------------------------------------------------- /backends/osg-gtk/src/osggtkdrawingarea.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // This is an implementation of SimpleViewer that is designed to be subclassed 7 | // and used as a GtkDrawingArea in a GTK application. Because of the implemention 8 | // of GTK, I was unable to derive from GtkWidget and instead had to "wrap" it. 9 | // Conceptually, however, you can think of an OSGGTKDrawingArea as both an OSG 10 | // Viewer AND GtkDrawingArea. 11 | // 12 | // While it is possible to use this class directly, it won't end up doing anything 13 | // interesting without calls to queueDraw, which ideally are done in the user's 14 | // subclass implementation (see: osgviewerGTK). 15 | class OSGGTKDrawingArea : public osgViewer::Viewer { 16 | GtkWidget* _widget; 17 | GdkGLConfig* _glconfig; 18 | GdkGLContext* _context; 19 | GdkGLDrawable* _drawable; 20 | 21 | osg::ref_ptr _gw; 22 | 23 | unsigned int _state; 24 | 25 | osgGA::EventQueue& _queue; 26 | 27 | static OSGGTKDrawingArea* _self(gpointer self) { 28 | return static_cast(self); 29 | } 30 | 31 | // A simple helper function to connect us to the various GTK signals. 32 | void _connect(const char* name, GCallback callback) { 33 | g_signal_connect(G_OBJECT(_widget), name, callback, this); 34 | } 35 | 36 | void _realize (GtkWidget*); 37 | void _unrealize (GtkWidget*); 38 | bool _expose_event (GtkWidget*, GdkEventExpose*); 39 | bool _configure_event (GtkWidget*, GdkEventConfigure*); 40 | bool _motion_notify_event (GtkWidget*, GdkEventMotion*); 41 | bool _button_press_event (GtkWidget*, GdkEventButton*); 42 | bool _key_press_event (GtkWidget*, GdkEventKey*); 43 | 44 | // The following functions are static "wrappers" so that we can invoke the 45 | // bound methods of a class instance by passing the "this" pointer as the 46 | // self argument and invoking it explicitly. 47 | static void _srealize(GtkWidget* widget, gpointer self) { 48 | _self(self)->_realize(widget); 49 | } 50 | 51 | static void _sunrealize(GtkWidget* widget, gpointer self) { 52 | _self(self)->_unrealize(widget); 53 | } 54 | 55 | static bool _sexpose_event(GtkWidget* widget, GdkEventExpose* expose, gpointer self) { 56 | return _self(self)->_expose_event(widget, expose); 57 | } 58 | 59 | static bool _sconfigure_event( 60 | GtkWidget* widget, 61 | GdkEventConfigure* event, 62 | gpointer self 63 | ) { 64 | return _self(self)->_configure_event(widget, event); 65 | } 66 | 67 | static bool _smotion_notify_event( 68 | GtkWidget* widget, 69 | GdkEventMotion* event, 70 | gpointer self 71 | ) { 72 | return _self(self)->_motion_notify_event(widget, event); 73 | } 74 | 75 | static bool _sbutton_press_event( 76 | GtkWidget* widget, 77 | GdkEventButton* event, 78 | gpointer self 79 | ) { 80 | return _self(self)->_button_press_event(widget, event); 81 | } 82 | 83 | static bool _skey_press_event( 84 | GtkWidget* widget, 85 | GdkEventKey* event, 86 | gpointer self 87 | ) { 88 | return _self(self)->_key_press_event(widget, event); 89 | } 90 | 91 | protected: 92 | // You can override these in your subclass if you'd like. :) 93 | // Right now they're fairly uninformative, but they could be easily extended. 94 | // Note that the "state" information isn't passed around to each function 95 | // but is instead stored and abstracted internally. See below. 96 | 97 | virtual void gtkRealize () {}; 98 | virtual void gtkUnrealize () {}; 99 | virtual bool gtkExpose () { 100 | return true; 101 | }; 102 | 103 | // The new width and height. 104 | virtual bool gtkConfigure(int, int) { 105 | return true; 106 | }; 107 | 108 | // The "normalized" coordinates of the mouse. 109 | virtual bool gtkMotionNotify(double, double) { 110 | return true; 111 | }; 112 | 113 | // The "normalized" coordinates of the mouse and the mouse button code on down. 114 | virtual bool gtkButtonPress(double, double, unsigned int) { 115 | return true; 116 | }; 117 | 118 | // The "normalized" coordinates of the mouse and mouse button code on release. 119 | virtual bool gtkButtonRelease(double, double, unsigned int) { 120 | return true; 121 | } 122 | 123 | // The X key value on down. 124 | virtual bool gtkKeyPress(unsigned int) { 125 | return true; 126 | }; 127 | 128 | // The X key value on release. 129 | virtual bool gtkKeyRelease(unsigned int) { 130 | return true; 131 | }; 132 | 133 | // These functions wrap state tests of the most recent state in the 134 | // GtkDrawingArea. 135 | 136 | inline bool stateShift() { 137 | return _state & GDK_SHIFT_MASK; 138 | } 139 | 140 | inline bool stateLock() { 141 | return _state & GDK_LOCK_MASK; 142 | } 143 | 144 | inline bool stateControl() { 145 | return _state & GDK_CONTROL_MASK; 146 | } 147 | 148 | inline bool stateMod() { 149 | return _state & ( 150 | GDK_MOD1_MASK | 151 | GDK_MOD2_MASK | 152 | GDK_MOD3_MASK | 153 | GDK_MOD4_MASK | 154 | GDK_MOD5_MASK 155 | ); 156 | } 157 | 158 | inline bool stateButton() { 159 | return _state & ( 160 | GDK_BUTTON1_MASK | 161 | GDK_BUTTON2_MASK | 162 | GDK_BUTTON3_MASK | 163 | GDK_BUTTON4_MASK | 164 | GDK_BUTTON5_MASK 165 | ); 166 | } 167 | 168 | public: 169 | OSGGTKDrawingArea (); 170 | ~OSGGTKDrawingArea (); 171 | 172 | bool createWidget(int, int); 173 | 174 | GtkWidget* getWidget() { 175 | return _widget; 176 | } 177 | 178 | bool gtkGLBegin() { 179 | if(_drawable and _context) return gdk_gl_drawable_gl_begin(_drawable, _context); 180 | 181 | else return false; 182 | } 183 | 184 | void gtkGLEnd() { 185 | if(_drawable) gdk_gl_drawable_gl_end(_drawable); 186 | } 187 | 188 | // Because of GTK's internal double buffering, I'm not sure if we're really 189 | // taking advantage of OpenGL's internal swapping. 190 | bool gtkGLSwap() { 191 | if(_drawable and gdk_gl_drawable_is_double_buffered(_drawable)) { 192 | gdk_gl_drawable_swap_buffers(_drawable); 193 | return true; 194 | } else { 195 | #if !defined(__APPLE__) 196 | glFlush(); 197 | #endif 198 | return false; 199 | } 200 | } 201 | 202 | void queueDraw() { 203 | gtk_widget_queue_draw(_widget); 204 | } 205 | }; 206 | -------------------------------------------------------------------------------- /backends/osg-gtk/src/osgviewerGTK.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "osggtkdrawingarea.h" 32 | #include "osgviewerGTK.hpp" 33 | #include "osg_interpreter.hpp" 34 | 35 | /* Implementation based on OSG GTK Example code */ 36 | 37 | const char* HELP_TEXT = 38 | "Use CTRL or SHIFT plus right-click to pull menu\n" 39 | "\n" 40 | "Modelica3D 2012" 41 | ; 42 | 43 | class OSG_GTK_Mod3DViewer : public OSGGTKDrawingArea { 44 | GtkWidget* _menu; 45 | 46 | double currentTime; // time since start of animation in s 47 | double tOffset; // offset 48 | double timeScaler; // scale time to slow things down or speed things up 49 | timeval startTime; // to store start of simulation 50 | unsigned int _tid; 51 | 52 | const proc3d::animation_queue& stored_animation; 53 | proc3d::animation_queue animation; 54 | std::map> nodes; 55 | std::map> materials; 56 | const osg::ref_ptr scene_content; 57 | const proc3d_osg_interpreter interpreter; 58 | 59 | bool _setFocus(GtkWidget* widget) { 60 | std::string name(gtk_label_get_label(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget))))); 61 | if (nodes.count(name) == 0) { 62 | std::cerr << "cannot find node: " << name << std::endl; 63 | return false; 64 | } 65 | osg::PositionAttitudeTransform * node = nodes[name]; 66 | osg::ref_ptr camTracker = new osgGA::NodeTrackerManipulator(); 67 | osg::Vec3d pos = node->getPosition(); 68 | camTracker->setHomePosition(pos + osg::Vec3d(1,1,1), pos, osg::Vec3d(0,0,1), false); 69 | camTracker->setTrackNode(node->getChild(0)); 70 | camTracker->setTrackerMode(osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION); 71 | camTracker->setRotationMode(osgGA::NodeTrackerManipulator::TRACKBALL); 72 | setCameraManipulator(camTracker); 73 | return true; 74 | } 75 | 76 | bool _clicked(GtkWidget* widget) { 77 | const char* text = gtk_label_get_label( 78 | GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget))) 79 | ); 80 | 81 | if(not strncmp(text, "Close", 5)) gtk_main_quit(); 82 | 83 | else if(not strncmp(text, "Open File", 9)) { 84 | GtkWidget* of = gtk_file_chooser_dialog_new( 85 | "Please select an OSG file...", 86 | GTK_WINDOW(gtk_widget_get_toplevel(getWidget())), 87 | GTK_FILE_CHOOSER_ACTION_OPEN, 88 | GTK_STOCK_CANCEL, 89 | GTK_RESPONSE_CANCEL, 90 | GTK_STOCK_OPEN, 91 | GTK_RESPONSE_ACCEPT, 92 | NULL 93 | ); 94 | 95 | if(gtk_dialog_run(GTK_DIALOG(of)) == GTK_RESPONSE_ACCEPT) { 96 | char* file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(of)); 97 | 98 | osg::ref_ptr model = osgDB::readNodeFile(file); 99 | 100 | if(model.valid()) { 101 | setSceneData(model.get()); 102 | 103 | queueDraw(); 104 | } 105 | 106 | g_free(file); 107 | } 108 | 109 | gtk_widget_destroy(of); 110 | } 111 | 112 | // Assume we're wanting FPS toggling. 113 | else { 114 | if(not _tid) { 115 | // start animation 116 | // get current time 117 | gettimeofday(&startTime, NULL); 118 | // instantiate timer 119 | _tid = g_timeout_add( 120 | 15, // 15ms equals roughly 60fps 121 | (GSourceFunc)(OSG_GTK_Mod3DViewer::timeout), 122 | this 123 | ); 124 | 125 | gtk_button_set_label(GTK_BUTTON(widget), "Pause"); 126 | } 127 | 128 | else { 129 | // pause animation 130 | tOffset = currentTime; 131 | g_source_remove(_tid); 132 | gtk_button_set_label(GTK_BUTTON(widget), "Start"); 133 | 134 | _tid = 0; 135 | } 136 | } 137 | 138 | return true; 139 | } 140 | 141 | protected: 142 | // Check right-click release to see if we need to popup our menu. 143 | bool gtkButtonRelease(double, double, unsigned int button) { 144 | if(button == 3 and (stateControl() or stateShift())) gtk_menu_popup( 145 | GTK_MENU(_menu), 146 | 0, 147 | 0, 148 | 0, 149 | 0, 150 | button, 151 | 0 152 | ); 153 | 154 | return true; 155 | } 156 | 157 | // Our "main" drawing pump. Since our app is just a model viewer, we use 158 | // click+motion as our criteria for issuing OpenGL refreshes. 159 | bool gtkMotionNotify(double, double) { 160 | if(stateButton()) queueDraw(); 161 | 162 | return true; 163 | } 164 | 165 | public: 166 | OSG_GTK_Mod3DViewer(const proc3d::animation_queue& q): 167 | OSGGTKDrawingArea (), 168 | _menu (gtk_menu_new()), 169 | _tid (0), 170 | stored_animation (q), 171 | scene_content(new osg::Group()), 172 | interpreter(scene_content, nodes, materials), 173 | timeScaler(1.0) { 174 | scene_content->setName("root"); 175 | 176 | gtk_widget_show_all(_menu); 177 | setSceneData(scene_content); 178 | getCamera()->setStats(new osg::Stats("omg")); 179 | 180 | 181 | restart_animation(); 182 | } 183 | 184 | ~OSG_GTK_Mod3DViewer() {} 185 | 186 | void setup_scene(const std::queue& s) { 187 | std::queue setup(s); 188 | while(!setup.empty()) { 189 | const proc3d::SetupOperation& op = setup.front(); 190 | boost::apply_visitor( interpreter, op ); 191 | setup.pop(); 192 | } 193 | 194 | // add menu item for each object 195 | for(std::map>::iterator i = nodes.begin(); i!= nodes.end(); i++) { 196 | std::cout << "adding menu item for node: " << i->first << std::endl; 197 | GtkWidget* item = gtk_menu_item_new_with_label((i->first).c_str()); 198 | gtk_menu_shell_append(GTK_MENU_SHELL(_menu), item); 199 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(OSG_GTK_Mod3DViewer::setFocus), this); 200 | } 201 | gtk_widget_show_all(_menu); 202 | 203 | /* activate first frame */ 204 | currentTime = 0.0; 205 | if (animation.empty()) 206 | tOffset = 0.0; 207 | else 208 | tOffset = proc3d::time_of(animation.top()); // only useful, if startTime != 0.0 209 | advance_animation(); 210 | } 211 | 212 | void restart_animation() { 213 | animation = proc3d::animation_queue(stored_animation); 214 | currentTime = 0.0; 215 | if (animation.empty()) 216 | tOffset = 0.0; 217 | else 218 | tOffset = proc3d::time_of(animation.top()); // only useful, if startTime != 0.0 219 | gettimeofday(&startTime, NULL); 220 | } 221 | 222 | void advance_animation() { 223 | timeval now; 224 | long seconds, useconds; 225 | 226 | // find out how many seconds have passed 227 | gettimeofday(&now, NULL); 228 | seconds = now.tv_sec - startTime.tv_sec; 229 | useconds = now.tv_usec - startTime.tv_usec; 230 | currentTime = tOffset + timeScaler*(seconds + 1e-6*useconds); 231 | 232 | // std::cout << "Update at t=" << currentTime << std::endl; 233 | 234 | if (animation.empty()) { 235 | restart_animation(); 236 | } else { 237 | AnimOperation op = animation.top(); 238 | // std::cout << "Anim command for t= " << proc3d::time_of(op) << std::endl; 239 | while (proc3d::time_of(op) <= currentTime && !animation.empty()) { 240 | boost::apply_visitor( interpreter, op ); 241 | animation.pop(); 242 | op = animation.top(); 243 | } 244 | } 245 | 246 | queueDraw(); 247 | } 248 | 249 | // Public so that we can use this as a callback in main(). 250 | static bool clicked(GtkWidget* widget, gpointer self) { 251 | return static_cast(self)->_clicked(widget); 252 | } 253 | 254 | // Public so that we can use this as a callback in main(). 255 | static bool setFocus(GtkWidget* widget, gpointer self) { 256 | return static_cast(self)->_setFocus(widget); 257 | } 258 | 259 | static bool timeout(void* self) { 260 | /* issue re-drawing */ 261 | static_cast(self) -> advance_animation(); 262 | return true; 263 | } 264 | }; 265 | 266 | int run_viewer(const proc3d::AnimationContext& context) { 267 | 268 | std::cout << "Starting GTK based viewer " << std::endl; 269 | std::cout << "Setup queue: " << context.setupOps.size() << " entries." << std::endl; 270 | std::cout << "Animation queue: " << context.deltaOps.size() << " entries." << std::endl; 271 | 272 | gtk_init(0, NULL); 273 | gtk_gl_init(0, NULL); 274 | 275 | OSG_GTK_Mod3DViewer da(context.deltaOps); 276 | da.setup_scene(context.setupOps); 277 | 278 | if(da.createWidget(640, 480)) { 279 | 280 | GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 281 | GtkWidget* vbox1 = gtk_vbox_new(false, 3); 282 | GtkWidget* vbox2 = gtk_vbox_new(false, 3); 283 | GtkWidget* hbox = gtk_hbox_new(false, 3); 284 | GtkWidget* label = gtk_label_new(""); 285 | GtkWidget* buttons[] = { 286 | //gtk_button_new_with_label("Open File"), 287 | gtk_button_new_with_label("Start"), 288 | gtk_button_new_with_label("Close") 289 | }; 290 | 291 | gtk_label_set_use_markup(GTK_LABEL(label), true); 292 | gtk_label_set_label(GTK_LABEL(label), HELP_TEXT); 293 | 294 | for(unsigned int i = 0; i < sizeof(buttons) / sizeof(GtkWidget*); i++) { 295 | gtk_box_pack_start( 296 | GTK_BOX(vbox2), 297 | buttons[i], 298 | false, 299 | false, 300 | 0 301 | ); 302 | 303 | g_signal_connect( 304 | G_OBJECT(buttons[i]), 305 | "clicked", 306 | G_CALLBACK(OSG_GTK_Mod3DViewer::clicked), 307 | &da 308 | ); 309 | } 310 | 311 | gtk_window_set_title(GTK_WINDOW(window), "Modelica3D OSG - GTK Viewer"); 312 | 313 | gtk_box_pack_start(GTK_BOX(hbox), vbox2, true, true, 2); 314 | gtk_box_pack_start(GTK_BOX(hbox), label, true, true, 2); 315 | 316 | gtk_box_pack_start(GTK_BOX(vbox1), da.getWidget(), true, true, 2); 317 | gtk_box_pack_start(GTK_BOX(vbox1), hbox, false, false, 2); 318 | 319 | gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), true); 320 | gtk_container_add(GTK_CONTAINER(window), vbox1); 321 | 322 | g_signal_connect( 323 | G_OBJECT(window), 324 | "delete_event", 325 | G_CALLBACK(gtk_main_quit), 326 | 0 327 | ); 328 | 329 | gtk_widget_show_all(window); 330 | gtk_main(); 331 | } 332 | 333 | else return 1; 334 | 335 | return 0; 336 | } 337 | 338 | extern "C" { 339 | 340 | void* osg_gtk_alloc_context() { 341 | return new GTKAnimationContext(); 342 | } 343 | 344 | void osg_gtk_free_context(void* context) { 345 | delete (GTKAnimationContext*) context; 346 | } 347 | 348 | } 349 | 350 | -------------------------------------------------------------------------------- /backends/osg-gtk/src/osgviewerGTK.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "animationContext.hpp" 25 | #include "operations.hpp" 26 | 27 | /* signal definitions */ 28 | #define RUN_ANIMATION 1 29 | 30 | extern int run_viewer(const proc3d::AnimationContext& context); 31 | 32 | class GTKAnimationContext : public proc3d::AnimationContext { 33 | 34 | virtual void handleSignal(const int signal) { 35 | switch (signal) { 36 | case RUN_ANIMATION: run_viewer(*this); 37 | } 38 | } 39 | }; 40 | 41 | extern "C" { 42 | 43 | void* osg_gtk_alloc_context(); 44 | 45 | void osg_gtk_free_context(void* context); 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /backends/osg-gtk/src/viewer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #include "osgviewerGTK.hpp" 23 | 24 | int main(int argc, char** argv) { 25 | return run_viewer(proc3d::AnimationContext()); 26 | } 27 | -------------------------------------------------------------------------------- /common/cmake/FindDBUS.cmake: -------------------------------------------------------------------------------- 1 | FIND_PATH( DBUS_INCLUDE_DIR dbus/dbus.h PATH_SUFFIXES /include/dbus-1.0) 2 | FIND_PATH( DBUS_INCLUDE_LIB_DIR dbus/dbus-arch-deps.h PATH_SUFFIXES /lib/dbus-1.0/include /lib64/dbus-1.0/include /lib/x86_64-linux-gnu/dbus-1.0/include/ /lib/i386-linux-gnu/dbus-1.0/include/) 3 | 4 | FIND_LIBRARY(DBUS_LIBRARY NAME dbus-1 PATHS /lib) 5 | 6 | IF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR AND DBUS_LIBRARY ) 7 | SET( DBUS_FOUND TRUE ) 8 | ENDIF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR AND DBUS_LIBRARY ) 9 | 10 | IF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR ) 11 | SET( DBUS_INCLUDES ${DBUS_INCLUDE_DIR} ${DBUS_INCLUDE_LIB_DIR} ) 12 | ENDIF( DBUS_INCLUDE_DIR AND DBUS_INCLUDE_LIB_DIR ) 13 | 14 | IF( DBUS_FOUND ) 15 | MESSAGE( STATUS "Found dbus: ${DBUS_LIBRARY}" ) 16 | ELSE( DBUS_FOUND ) 17 | IF( DBUS_FIND_REQUIRED ) 18 | MESSAGE( FATAL_ERROR "Could not find dbus ${DBUS_INCLUDE_LIB_DIR}" ) 19 | ENDIF( DBUS_FIND_REQUIRED ) 20 | ENDIF( DBUS_FOUND ) 21 | 22 | 23 | -------------------------------------------------------------------------------- /common/cmake/FindGLFW.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libglfw 2 | # Once done this will define 3 | # LIBGLFW_FOUND - System has LibXml2 4 | # LIBGLFW_INCLUDE_DIRS - The LibXml2 include directories 5 | # LIBGLFW_LIBRARIES - The libraries needed to use LibXml2 6 | 7 | find_path(LIBGLFW_INCLUDE_DIR GL/glfw.h) 8 | 9 | find_library(LIBGLFW_LIBRARY NAMES glfw libglfw) 10 | 11 | set(LIBGLFW_LIBRARIES ${LIBGLFW_LIBRARY} ) 12 | set(LIBGLFW_INCLUDE_DIRS ${LIBGLFW_INCLUDE_DIR} ) 13 | 14 | include(FindPackageHandleStandardArgs) 15 | # handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE 16 | # if all listed variables are TRUE 17 | find_package_handle_standard_args(libglfw DEFAULT_MSG 18 | LIBGLFW_LIBRARY LIBGLFW_INCLUDE_DIR) 19 | 20 | mark_as_advanced(LIBGLFW_INCLUDE_DIR LIBGLFW_LIBRARY) -------------------------------------------------------------------------------- /common/cmake/FindGtkGl.cmake: -------------------------------------------------------------------------------- 1 | #use pkg-config to find various modues 2 | INCLUDE(FindPkgConfig OPTIONAL) 3 | 4 | IF(PKG_CONFIG_FOUND) 5 | 6 | INCLUDE(FindPkgConfig) 7 | 8 | PKG_CHECK_MODULES(GTK gtk+-2.0) 9 | 10 | IF(WIN32) 11 | PKG_CHECK_MODULES(GTKGL gtkglext-win32-1.0) 12 | ELSE() 13 | PKG_CHECK_MODULES(GTKGL gtkglext-1.0) 14 | ENDIF() 15 | 16 | ENDIF() 17 | -------------------------------------------------------------------------------- /common/cmake/FindOMC.cmake: -------------------------------------------------------------------------------- 1 | # Tries to detect omc modelica-library and include dirs, does not search for binary yet 2 | 3 | # This will also search ${CMAKE_PREFIX_PATH}/include automagically 4 | find_path(OMC_INCLUDE_DIR openmodelica.h PATH_SUFFIXES omc/c) 5 | 6 | find_program(OMC_COMPILER NAMES omc) 7 | 8 | # This will _not_ search ${CMAKE_PREFIX_PATH}/lib automagically, we need to give a search hint 9 | find_path(OMC_MOD_LIB_DIR "ModelicaReference/package.mo" 10 | PATHS "${CMAKE_LIBRARY_PATH}/omlibrary" 11 | "${CMAKE_PREFIX_PATH}/lib/omlibrary" /usr/lib/omlibrary) 12 | 13 | # This will also search ${CMAKE_PREFIX_PATH}/lib automagically 14 | find_library(OMC_RUNTIME omcruntime PATH_SUFFIXES omc) 15 | 16 | if ( OMC_INCLUDE_DIR AND OMC_MOD_LIB_DIR AND OMC_RUNTIME AND OMC_COMPILER) 17 | set( OMC_FOUND TRUE ) 18 | endif() 19 | 20 | if( OMC_INCLUDE_DIR) 21 | set( OMC_INCLUDES "${OMC_INCLUDE_DIR}") 22 | endif ( OMC_INCLUDE_DIR ) 23 | 24 | if( OMC_RUNTIME) 25 | get_filename_component(OMC_LIBRARY_DIR ${OMC_RUNTIME} PATH) 26 | endif( OMC_RUNTIME) 27 | 28 | if( OMC_FOUND ) 29 | message( STATUS "Found omc runtime : ${OMC_RUNTIME}" ) 30 | message( STATUS "Found omc compiler : ${OMC_COMPILER}" ) 31 | else( OMC_FOUND ) 32 | if( OMC_FIND_REQUIRED ) 33 | message( FATAL_ERROR "Could not find the openmodelica installation" ) 34 | endif( OMC_FIND_REQUIRED ) 35 | endif( OMC_FOUND ) 36 | 37 | # vi:ts=4:sw=4:expandtab 38 | -------------------------------------------------------------------------------- /examples/multibody/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Modelica library to install 2 | set(multibody_src "${CMAKE_SOURCE_DIR}/examples/multibody/src/modelica/") 3 | 4 | install(FILES 5 | "${multibody_src}/Internal.mo" 6 | "${multibody_src}/Pendulum.mo" 7 | "${multibody_src}/DoublePendulum.mo" 8 | "${multibody_src}/Engine1b.mo" 9 | DESTINATION "lib/omlibrary-modelica3d") 10 | -------------------------------------------------------------------------------- /examples/multibody/src/modelica/DoublePendulum.mo: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Christoph Höger, All Rights Reserved 3 | 4 | This file is part of modelica3d 5 | (https://mlcontrol.uebb.tu-berlin.de/redmine/projects/modelica3d-public). 6 | 7 | Licensed under the Modelica License 2 8 | */ 9 | 10 | within Modelica.Mechanics.MultiBody.Examples.Elementary; 11 | model DoublePendulum 12 | "Simple double pendulum with two revolute joints and two bodies" 13 | 14 | extends Modelica.Icons.Example; 15 | 16 | /* enable M3D Visualization */ 17 | import M3D=ModelicaServices.Modelica3D; 18 | 19 | inner M3D.Controller m3d_control; 20 | 21 | inner Modelica.Mechanics.MultiBody.World world annotation (Placement( 22 | transformation(extent={{-88,0},{-68,20}}, rotation=0))); 23 | Modelica.Mechanics.MultiBody.Joints.Revolute revolute1(useAxisFlange=true,phi(fixed=true), 24 | w(fixed=true)) annotation (Placement(transformation(extent={{-48,0}, 25 | {-28,20}}, rotation=0))); 26 | Modelica.Mechanics.Rotational.Components.Damper damper( 27 | d=0.1) 28 | annotation (Placement(transformation(extent={{-48,40},{-28,60}}, rotation=0))); 29 | Modelica.Mechanics.MultiBody.Parts.BodyBox boxBody1(r={0.5,0,0}, width=0.06) 30 | annotation (Placement(transformation(extent={{-10,0},{10,20}}, rotation=0))); 31 | Modelica.Mechanics.MultiBody.Joints.Revolute revolute2(phi(fixed=true), w( 32 | fixed=true)) annotation (Placement(transformation(extent={{32,0},{ 33 | 52,20}}, rotation=0))); 34 | Modelica.Mechanics.MultiBody.Parts.BodyBox boxBody2(r={0.5,0,0}, width=0.06) 35 | annotation (Placement(transformation(extent={{74,0},{94,20}}, rotation=0))); 36 | equation 37 | 38 | connect(damper.flange_b, revolute1.axis) annotation (Line(points={{-28,50},{ 39 | -24,50},{-24,28},{-38,28},{-38,20}}, color={0,0,0})); 40 | connect(revolute1.support, damper.flange_a) annotation (Line(points={{-44,20}, 41 | {-44,28},{-58,28},{-58,50},{-48,50}}, color={0,0,0})); 42 | connect(revolute1.frame_b, boxBody1.frame_a) 43 | annotation (Line( 44 | points={{-28,10},{-10,10}}, 45 | color={95,95,95}, 46 | thickness=0.5)); 47 | connect(revolute2.frame_b, boxBody2.frame_a) 48 | annotation (Line( 49 | points={{52,10},{74,10}}, 50 | color={95,95,95}, 51 | thickness=0.5)); 52 | connect(boxBody1.frame_b, revolute2.frame_a) 53 | annotation (Line( 54 | points={{10,10},{32,10}}, 55 | color={95,95,95}, 56 | thickness=0.5)); 57 | connect(world.frame_b, revolute1.frame_a) 58 | annotation (Line( 59 | points={{-68,10},{-48,10}}, 60 | color={95,95,95}, 61 | thickness=0.5)); 62 | annotation ( 63 | experiment(StopTime=3), 64 | Diagram(coordinateSystem( 65 | preserveAspectRatio=true, 66 | extent={{-100,-100},{100,100}}, 67 | grid={2,2}), graphics), 68 | Documentation(info=" 69 |

70 | This example demonstrates that by using joint and body 71 | elements animation is automatically available. Also the revolute 72 | joints are animated. Note, that animation of every component 73 | can be switched of by setting the first parameter animation 74 | to false or by setting enableAnimation in the world 75 | object to false to switch off animation of all components. 76 |

77 | 78 |
79 | \"model 81 |
82 | 83 | ")); 84 | end DoublePendulum; 85 | -------------------------------------------------------------------------------- /examples/multibody/src/modelica/Engine1b.mo: -------------------------------------------------------------------------------- 1 | within Modelica.Mechanics.MultiBody.Examples.Loops; 2 | model Engine1b 3 | "Model of one cylinder engine with gas force and preparation for assembly joint JointRRP" 4 | import SI = Modelica.SIunits; 5 | extends Modelica.Icons.Example; 6 | 7 | extends Utilities.Engine1bBase; 8 | 9 | /* enable M3D Visualization */ 10 | import M3D=ModelicaServices.Modelica3D; 11 | inner M3D.Controller m3d_control; 12 | 13 | Joints.RevolutePlanarLoopConstraint B2( 14 | n={1,0,0}, 15 | cylinderLength=0.02, 16 | cylinderDiameter=0.05) annotation (Placement(transformation(extent={{40,20}, 17 | {60,40}}, rotation=0))); 18 | Modelica.Mechanics.MultiBody.Joints.Revolute B1( 19 | n={1,0,0}, 20 | cylinderLength=0.02, 21 | cylinderDiameter=0.05) 22 | annotation (Placement(transformation(extent={{40,-20}, 23 | {60,0}}, rotation=0))); 24 | Modelica.Mechanics.MultiBody.Joints.Prismatic Cylinder(useAxisFlange=true, 25 | boxWidth=0.02, n={0,-1,0}) 26 | annotation (Placement(transformation( 27 | origin={50,97}, 28 | extent={{-10,-10},{10,10}}, 29 | rotation=270))); 30 | Parts.FixedTranslation Rod1(r={0,0.2,0}, animation=false) 31 | annotation (Placement(transformation( 32 | origin={70,10}, 33 | extent={{-10,-10},{10,10}}, 34 | rotation=90))); 35 | Parts.FixedTranslation Rod3(r={0,-0.1,0}, animation=false) 36 | annotation (Placement(transformation( 37 | origin={50,58}, 38 | extent={{10,-10},{-10,10}}, 39 | rotation=90))); 40 | equation 41 | connect(B1.frame_b, Rod1.frame_a) annotation (Line( 42 | points={{60,-10},{70,-10},{70,0}}, 43 | color={95,95,95}, 44 | thickness=0.5)); 45 | connect(Rod1.frame_b, B2.frame_b) annotation (Line( 46 | points={{70,20},{70,30},{60,30}}, 47 | color={95,95,95}, 48 | thickness=0.5)); 49 | connect(Cylinder.frame_b, Rod3.frame_a) annotation (Line( 50 | points={{50,87},{50,68}}, 51 | color={95,95,95}, 52 | thickness=0.5)); 53 | connect(B2.frame_a, Rod3.frame_b) annotation (Line( 54 | points={{40,30},{30,30},{30,44},{50,44},{50,48}}, 55 | color={95,95,95}, 56 | thickness=0.5)); 57 | connect(cylPosition.frame_b, Cylinder.frame_a) annotation (Line( 58 | points={{-20.5,110},{50,110},{50,107}}, 59 | color={95,95,95}, 60 | thickness=0.5)); 61 | connect(gasForce.flange_a, Cylinder.support) annotation (Line(points={{119, 62 | 107},{119,112},{70,112},{70,101},{56,101}}, color={0,127,0})); 63 | connect(Cylinder.axis, gasForce.flange_b) annotation (Line(points={{56,89},{ 64 | 71,89},{71,80},{119,80},{119,87}}, color={0,127,0})); 65 | connect(Piston.frame_a, Rod3.frame_a) annotation (Line( 66 | points={{120,63},{120,75},{50,75},{50,68}}, 67 | color={95,95,95}, 68 | thickness=0.5)); 69 | connect(B1.frame_b, Rod2.frame_a) annotation (Line( 70 | points={{60,-10},{120,-10},{120,0}}, 71 | color={95,95,95}, 72 | thickness=0.5)); 73 | connect(Mid.frame_b, B1.frame_a) annotation (Line( 74 | points={{50,-43},{57,-43},{57,-28},{30,-28},{30,-10},{40,-10}}, 75 | color={95,95,95}, 76 | thickness=0.5)); 77 | annotation ( 78 | experiment(StopTime=0.5), 79 | Diagram(coordinateSystem( 80 | preserveAspectRatio=true, 81 | extent={{-100,-120},{150,120}}, 82 | grid={1,1}), graphics={ 83 | Rectangle( 84 | extent={{3,117},{88,-23}}, 85 | lineColor={255,0,0}, 86 | lineThickness=0.5), 87 | Text( 88 | extent={{65,-30},{145,-39}}, 89 | lineColor={255,0,0}, 90 | lineThickness=0.5, 91 | textString="jointRRP in model"), 92 | Text( 93 | extent={{66,-34},{141,-52}}, 94 | lineColor={255,0,0}, 95 | lineThickness=0.5, 96 | textString="Loops.Engine1b_analytic")}), 97 | Documentation(info=" 98 |

99 | This is a model of the mechanical part of one cylinder of an engine. 100 | It is similiar to 101 | Loops.Engine1a. 102 | The difference is that a simple 103 | model for the gas force in the cylinder is added and that the 104 | model is restructured in such a way, that the central part of 105 | the planar kinematic loop can be easily replaced by the 106 | assembly joint \"Modelica.Mechanics.MultiBody.Joints.Assemblies.JointRRP\". 107 | This exchange of the kinematic loop is shown in 108 | Loops.Engine1b_analytic. 109 | The advantage of using JointRRP is, that the 110 | non-linear algebraic equation of this loop is solved analytically, and 111 | not numerically as in this model (Engine1b). 112 |

113 |

114 | An animation of this example is shown in the figure below. 115 |

116 |

117 | \"model 118 |

119 | ")); 120 | end Engine1b; 121 | -------------------------------------------------------------------------------- /examples/multibody/src/modelica/Internal.mo: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Christoph Höger, All Rights Reserved 3 | 4 | This file is part of modelica3d 5 | (https://mlcontrol.uebb.tu-berlin.de/redmine/projects/modelica3d-public). 6 | 7 | Licensed under the Modelica License 2 8 | */ 9 | 10 | within Modelica.Utilities; 11 | package Internal 12 | "Internal components that a user should usually not directly utilize" 13 | partial package PartialModelicaServices 14 | "Interfaces of components requiring a tool specific implementation" 15 | package Animation "Models and functions for 3-dim. animation" 16 | 17 | partial model PartialShape 18 | "Different visual shapes with variable size; all data have to be set as modifiers" 19 | 20 | import SI = Modelica.SIunits; 21 | import Modelica.Mechanics.MultiBody.Frames; 22 | import Modelica.Mechanics.MultiBody.Types; 23 | 24 | parameter Types.ShapeType shapeType="box" 25 | "Type of shape (box, sphere, cylinder, pipecylinder, cone, pipe, beam, gearwheel, spring)"; 26 | input Frames.Orientation R=Frames.nullRotation() 27 | "Orientation object to rotate the world frame into the object frame" 28 | annotation(Dialog); 29 | input SI.Position r[3]={0,0,0} 30 | "Position vector from origin of world frame to origin of object frame, resolved in world frame" 31 | annotation(Dialog); 32 | input SI.Position r_shape[3]={0,0,0} 33 | "Position vector from origin of object frame to shape origin, resolved in object frame" 34 | annotation(Dialog); 35 | input Real lengthDirection[3](each final unit="1")={1,0,0} 36 | "Vector in length direction, resolved in object frame" 37 | annotation(Dialog); 38 | input Real widthDirection[3](each final unit="1")={0,1,0} 39 | "Vector in width direction, resolved in object frame" 40 | annotation(Dialog); 41 | input SI.Length length=0 "Length of visual object" annotation(Dialog); 42 | input SI.Length width=0 "Width of visual object" annotation(Dialog); 43 | input SI.Length height=0 "Height of visual object" annotation(Dialog); 44 | input Types.ShapeExtra extra=0.0 45 | "Additional size data for some of the shape types" annotation(Dialog); 46 | input Real color[3]={255,0,0} "Color of shape" annotation(Dialog); 47 | input Types.SpecularCoefficient specularCoefficient = 0.7 48 | "Reflection of ambient light (= 0: light is completely absorbed)" 49 | annotation(Dialog); 50 | // Real rxry[3, 2]; 51 | annotation ( 52 | Icon(coordinateSystem( 53 | preserveAspectRatio=true, 54 | extent={{-100,-100},{100,100}}, 55 | grid={2,2}), graphics={ 56 | Rectangle( 57 | extent={{-100,-100},{80,60}}, 58 | lineColor={0,0,255}, 59 | fillColor={255,255,255}, 60 | fillPattern=FillPattern.Solid), 61 | Polygon( 62 | points={{-100,60},{-80,100},{100,100},{80,60},{-100,60}}, 63 | lineColor={0,0,255}, 64 | fillColor={192,192,192}, 65 | fillPattern=FillPattern.Solid), 66 | Polygon( 67 | points={{100,100},{100,-60},{80,-100},{80,60},{100,100}}, 68 | lineColor={0,0,255}, 69 | fillColor={160,160,164}, 70 | fillPattern=FillPattern.Solid), 71 | Text( 72 | extent={{-100,-100},{80,60}}, 73 | lineColor={0,0,0}, 74 | textString="%shapeType"), 75 | Text( 76 | extent={{-132,160},{128,100}}, 77 | textString="%name", 78 | lineColor={0,0,255})}), 79 | Documentation(info=" 80 | 81 |

82 | This model is documented at 83 | Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape. 84 |

85 | 86 | 87 | ")); 88 | 89 | import Bus=ModelicaServices.modbus; 90 | import ModelicaServices.modcount; 91 | 92 | import Id=ModelicaServices.modcount.HeapString; 93 | import M3D=ModelicaServices.Modelica3D; 94 | import Modelica.Math.Vectors.isEqual; 95 | 96 | function shapeDescrTo3D 97 | input M3D.State state; 98 | input String descr; 99 | input Real length, width, height; 100 | input Real[3] at; 101 | output Id id; 102 | protected 103 | 104 | algorithm 105 | if (descr == "box") then 106 | id := M3D.createBoxAt(state, width, height, length, at[1], at[2], at[3]); 107 | elseif (descr == "cone") then 108 | id := M3D.createConeAt(state, length, width, at[1], at[2], at[3] ); 109 | elseif (descr == "sphere") then 110 | id := M3D.createSphere(state, length); 111 | elseif (descr == "cylinder") then 112 | id := M3D.createCylinderAt(state, length, width, at[1], at[2], at[3]); 113 | elseif (descr == "pipecylinder") then 114 | // not yet supported 115 | Modelica.Utilities.Streams.print("Error: Visualization of pipecylinders has not been implemented yet!"); 116 | id := Id("UNKNOWN"); 117 | elseif (descr == "pipe") then 118 | // not yet supported 119 | Modelica.Utilities.Streams.print("Error: Visualization of pipes has not been implemented yet!"); 120 | id := Id("UNKNOWN"); 121 | elseif (descr == "beam") then 122 | // not yet supported 123 | Modelica.Utilities.Streams.print("Error: Visualization of beams has not been implemented yet!"); 124 | id := Id("UNKNOWN"); 125 | elseif (descr == "gearwheel") then 126 | // not yet supported 127 | Modelica.Utilities.Streams.print("Error: Visualization of gearwheels has not been implemented yet!"); 128 | id := Id("UNKNOWN"); 129 | elseif (descr == "spring") then 130 | // not yet supported 131 | Modelica.Utilities.Streams.print("Error: Visualization of springs has not been implemented yet!"); 132 | id := Id("UNKNOWN"); 133 | else 134 | // assume it is a filename 135 | id := M3D.loadFromFile(state, Modelica.Utilities.Files.fullPathName(descr), at[1], at[2], at[3]); 136 | end if; 137 | 138 | end shapeDescrTo3D; 139 | 140 | outer M3D.Controller m3d_control; 141 | 142 | Id id; 143 | Id mat; 144 | modcount.Context initContext = modcount.Context(); 145 | String res; 146 | 147 | discrete Real[3] pos; 148 | discrete Real[3,3] oldT; 149 | discrete Boolean moved; 150 | discrete Boolean rotated; 151 | // disable initial equation for now, since there is some bug in initial residuals 152 | //initial equation 153 | // pre(oldT) = R.T; 154 | // pre(pos) = r + Frames.resolve1(R, r_shape); 155 | initial algorithm 156 | if modcount.get(initContext) <> 1 then 157 | id := shapeDescrTo3D(m3d_control.state, shapeType, length, width, height, lengthDirection); 158 | mat := M3D.createMaterial(m3d_control.state); 159 | M3D.setAmbientColor(m3d_control.state, mat, color[1] / 255, color[2] / 255, color[3] / 255, 1.0, time); 160 | M3D.setSpecularColor(m3d_control.state, mat, specularCoefficient * (color[1] / 255), 161 | specularCoefficient * color[2] / 255, specularCoefficient * color[3] / 255, 1.0, time); 162 | 163 | M3D.applyMaterial(m3d_control.state, id, mat); 164 | modcount.set(initContext, 1); 165 | end if; 166 | algorithm 167 | when m3d_control.send and modcount.get(initContext) == 1 then 168 | 169 | // check for rotation 170 | rotated := not Modelica.Math.Matrices.isEqual(R.T, oldT); 171 | if noEvent(rotated) then 172 | res := M3D.rotate(m3d_control.state, id, R.T, time); 173 | end if; 174 | oldT := R.T; 175 | 176 | // check for translation 177 | pos := r + Frames.resolve1(R, r_shape); 178 | moved := not Modelica.Math.Vectors.isEqual(pos, pre(pos)); 179 | if noEvent(moved) then 180 | res := M3D.moveTo(m3d_control.state, id, pos, time); 181 | end if; 182 | 183 | end when; 184 | end PartialShape; 185 | end Animation; 186 | 187 | annotation (Documentation(info=" 188 | 189 |

190 | This package contains interfaces of a set of functions and models used in the 191 | Modelica Standard Library that requires a tool specific implementation. 192 | There is an associated package called ModelicaServices. A tool vendor 193 | should provide a proper implementation of this library for the corresponding 194 | tool. The default implementation is \"do nothing\". 195 | In the Modelica Standard Library, the models and functions of ModelicaServices 196 | are used. 197 |

198 | 199 | ")); 200 | end PartialModelicaServices; 201 | 202 | protected 203 | package FileSystem 204 | "Internal package with external functions as interface to the file system" 205 | extends Modelica.Icons.Library; 206 | 207 | function mkdir "Make directory (POSIX: 'mkdir')" 208 | extends Modelica.Icons.Function; 209 | input String directoryName "Make a new directory"; 210 | external "C" ModelicaInternal_mkdir(directoryName); 211 | 212 | annotation(Library="ModelicaExternalC"); 213 | end mkdir; 214 | 215 | function rmdir "Remove empty directory (POSIX function 'rmdir')" 216 | extends Modelica.Icons.Function; 217 | input String directoryName "Empty directory to be removed"; 218 | external "C" ModelicaInternal_rmdir(directoryName); 219 | 220 | annotation(Library="ModelicaExternalC"); 221 | end rmdir; 222 | 223 | function stat "Inquire file information (POSIX function 'stat')" 224 | extends Modelica.Icons.Function; 225 | input String name "Name of file, directory, pipe etc."; 226 | output Types.FileType fileType "Type of file"; 227 | external "C" fileType= ModelicaInternal_stat(name); 228 | 229 | annotation(Library="ModelicaExternalC"); 230 | end stat; 231 | 232 | function rename "Rename existing file or directory (C function 'rename')" 233 | extends Modelica.Icons.Function; 234 | input String oldName "Current name"; 235 | input String newName "New name"; 236 | external "C" ModelicaInternal_rename(oldName, newName); 237 | 238 | annotation(Library="ModelicaExternalC"); 239 | end rename; 240 | 241 | function removeFile "Remove existing file (C function 'remove')" 242 | extends Modelica.Icons.Function; 243 | input String fileName "File to be removed"; 244 | external "C" ModelicaInternal_removeFile(fileName); 245 | 246 | annotation(Library="ModelicaExternalC"); 247 | end removeFile; 248 | 249 | function copyFile 250 | "Copy existing file (C functions 'fopen', 'getc', 'putc', 'fclose')" 251 | extends Modelica.Icons.Function; 252 | input String fromName "Name of file to be copied"; 253 | input String toName "Name of copy of file"; 254 | external "C" ModelicaInternal_copyFile(fromName, toName); 255 | 256 | annotation(Library="ModelicaExternalC"); 257 | end copyFile; 258 | 259 | function readDirectory 260 | "Read names of a directory (POSIX functions opendir, readdir, closedir)" 261 | extends Modelica.Icons.Function; 262 | input String directory 263 | "Name of the directory from which information is desired"; 264 | input Integer nNames 265 | "Number of names that are returned (inquire with getNumberOfFiles)"; 266 | output String names[nNames] 267 | "All file and directory names in any order from the desired directory"; 268 | external "C" ModelicaInternal_readDirectory(directory,nNames,names); 269 | 270 | annotation(Library="ModelicaExternalC"); 271 | end readDirectory; 272 | 273 | function getNumberOfFiles 274 | "Get number of files and directories in a directory (POSIX functions opendir, readdir, closedir)" 275 | extends Modelica.Icons.Function; 276 | input String directory "Directory name"; 277 | output Integer result 278 | "Number of files and directories present in 'directory'"; 279 | external "C" result = ModelicaInternal_getNumberOfFiles(directory); 280 | 281 | annotation(Library="ModelicaExternalC"); 282 | end getNumberOfFiles; 283 | 284 | annotation ( 285 | Documentation(info=" 286 |

287 | Package Internal.FileSystem is an internal package that contains 288 | low level functions as interface to the file system. 289 | These functions should not be called directly in a scripting 290 | environment since more convenient functions are provided 291 | in packages Files and Systems. 292 |

293 |

294 | Note, the functions in this package are direct interfaces to 295 | functions of POSIX and of the standard C library. Errors 296 | occuring in these functions are treated by triggering 297 | a Modelica assert. Therefore, the functions in this package 298 | return only for a successful operation. Furthermore, the 299 | representation of a string is hidden by this interface, 300 | especially if the operating system supports Unicode characters. 301 |

302 | ")); 303 | end FileSystem; 304 | end Internal; 305 | -------------------------------------------------------------------------------- /examples/multibody/src/modelica/Pendulum.mo: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Christoph Höger, All Rights Reserved 3 | 4 | This file is part of modelica3d 5 | (https://mlcontrol.uebb.tu-berlin.de/redmine/projects/modelica3d-public). 6 | 7 | Licensed under the Modelica License 2 8 | */ 9 | 10 | within Modelica.Mechanics.MultiBody.Examples.Elementary; 11 | model Pendulum "Simple pendulum with one revolute joint and one body" 12 | 13 | extends Modelica.Icons.Example; 14 | 15 | /* enable M3D Visualization */ 16 | import M3D=ModelicaServices.Modelica3D; 17 | 18 | inner M3D.Controller m3d_control; 19 | 20 | inner Modelica.Mechanics.MultiBody.World world(gravityType=Modelica.Mechanics.MultiBody.Types.GravityTypes. 21 | UniformGravity) annotation (Placement(transformation(extent={{-60,0},{ 22 | -40,20}}, rotation=0))); 23 | Modelica.Mechanics.MultiBody.Joints.Revolute rev(n={0,0,1},useAxisFlange=true, 24 | phi(fixed=true), 25 | w(fixed=true)) annotation (Placement(transformation(extent={{ 26 | -20,0},{0,20}}, rotation=0))); 27 | Modelica.Mechanics.Rotational.Components.Damper damper( 28 | d=0.1) 29 | annotation (Placement(transformation(extent={{-20,40},{0,60}}, rotation=0))); 30 | Modelica.Mechanics.MultiBody.Parts.Body body(m=1.0, r_CM={0.5,0,0}) 31 | annotation (Placement(transformation(extent={{20,0},{40,20}}, rotation=0))); 32 | equation 33 | connect(world.frame_b, rev.frame_a) 34 | annotation (Line( 35 | points={{-40,10},{-20,10}}, 36 | color={95,95,95}, 37 | thickness=0.5)); 38 | connect(damper.flange_b, rev.axis) annotation (Line(points={{0,50},{4,50},{4, 39 | 26},{-10,26},{-10,20}}, color={0,0,0})); 40 | connect(rev.support, damper.flange_a) annotation (Line(points={{-16,20},{-16, 41 | 26},{-28,26},{-28,50},{-20,50}}, color={0,0,0})); 42 | connect(body.frame_a, rev.frame_b) annotation (Line( 43 | points={{20,10},{0,10}}, 44 | color={95,95,95}, 45 | thickness=0.5)); 46 | annotation ( 47 | experiment(StopTime=5), 48 | Diagram(coordinateSystem( 49 | preserveAspectRatio=true, 50 | extent={{-100,-100},{100,100}}, 51 | grid={2,2}), graphics), 52 | Documentation(info=" 53 |

54 | This simple model demonstrates that by just dragging components 55 | default animation is defined that shows the structure of the 56 | assembled system. 57 |

58 | \"model 60 |

61 | ")); 62 | end Pendulum; 63 | -------------------------------------------------------------------------------- /lib/mod3d/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(mod3d_src "${CMAKE_SOURCE_DIR}/lib/mod3d/src/") 2 | 3 | if(USE_OMC) 4 | # Modelica library to install 5 | install(FILES "${mod3d_src}/modelica/Modelica3D\ 3.2.1/package.mo" 6 | DESTINATION "${OMC_MOD_LIB_DIR}/${MODELICA_SERVICES_LIBRARY}/Modelica3D") 7 | install(FILES "${mod3d_src}/modelica/package.mo" 8 | DESTINATION "${OMC_MOD_LIB_DIR}/${MODELICA_SERVICES_LIBRARY}") 9 | endif(USE_OMC) 10 | -------------------------------------------------------------------------------- /lib/mod3d/src/modelica/Modelica3D 3.2.1/package.mo: -------------------------------------------------------------------------------- 1 | within ModelicaServices; 2 | package Modelica3D 3 | extends Modelica.Icons.Package; 4 | 5 | import Id = ModelicaServices.modcount.HeapString; 6 | import ModelicaServices.modcount.{Context,HeapString,getString,setString}; 7 | 8 | import ModelicaServices.modbus.{Connection,Message,sendMessage,addInteger,addReal,addString}; 9 | 10 | constant String TARGET = "de.tuberlin.uebb.modelica3d.server"; 11 | constant String OBJECT = "/de/tuberlin/uebb/modelica3d/server"; 12 | constant String INTERFACE = "de.tuberlin.uebb.modelica3d.api"; 13 | 14 | class Controller 15 | discrete Connection conn = Connection("de.tuberlin.uebb.modelica3d.client"); 16 | discrete Context context = Context(); 17 | 18 | parameter Integer framerate = 30; 19 | parameter Modelica.SIunits.Time updateInterval = 1 / framerate; 20 | parameter Boolean autostop = true; 21 | 22 | output Boolean send; 23 | 24 | equation 25 | send = sample(1e-08, updateInterval); 26 | 27 | algorithm 28 | when terminal() then 29 | if autostop then stop(conn, context); end if; 30 | end when; 31 | annotation ( 32 | defaultComponentName="m3d_control", 33 | defaultComponentPrefixes="inner", 34 | missingInnerMessage="No \"m3d_control\" component is defined."); 35 | end Controller; 36 | 37 | function objectId 38 | input String s; 39 | output Id id = HeapString(s); 40 | end objectId; 41 | 42 | 43 | function createMaterial 44 | input Connection conn; 45 | input Context context; 46 | input Id id; 47 | protected 48 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_material"); 49 | algorithm 50 | setString(id,"material_" + String(modcount.increase_get(context))); 51 | addString(msg, "reference", getString(id)); 52 | sendMessage(conn, msg); 53 | end createMaterial; 54 | 55 | 56 | function applyMaterial 57 | input Connection conn; 58 | input Context context; 59 | input Id obj; 60 | input Id mat; 61 | output String res; 62 | protected 63 | Message msg = Message(TARGET, OBJECT, INTERFACE, "apply_material"); 64 | algorithm 65 | addString(msg, "reference", getString(obj)); 66 | addString(msg, "material", getString(mat)); 67 | res := sendMessage(conn, msg); 68 | end applyMaterial; 69 | 70 | 71 | function createBox 72 | input Connection conn; 73 | input Context context; 74 | input Real length, width, height; 75 | input Id id; 76 | protected 77 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_box"); 78 | algorithm 79 | setString(id,HeapString("box_" + String(modcount.increase_get(context)))); 80 | addString(msg, "reference", getString(id)); 81 | addReal(msg, "length", length); 82 | addReal(msg, "width", width); 83 | addReal(msg, "height", height); 84 | sendMessage(conn, msg); 85 | end createBox; 86 | 87 | 88 | function createBoxAt 89 | input Connection conn; 90 | input Context context; 91 | input Real length, width, height; 92 | input Real tx,ty,tz; 93 | input Id id; 94 | protected 95 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_box"); 96 | algorithm 97 | setString(id,"box_" + String(modcount.increase_get(context))); 98 | addString(msg, "reference", getString(id)); 99 | addReal(msg, "length", length); 100 | addReal(msg, "width", width); 101 | addReal(msg, "height", height); 102 | addReal(msg, "tx", tx); 103 | addReal(msg, "ty", ty); 104 | addReal(msg, "tz", tz); 105 | sendMessage(conn, msg); 106 | end createBoxAt; 107 | 108 | function loadFromFile 109 | input Connection conn; 110 | input Context context; 111 | input String fileName; 112 | input Real tx,ty,tz; 113 | input Id id; 114 | protected 115 | Message msg = Message(TARGET, OBJECT, INTERFACE, "loadFromFile"); 116 | algorithm 117 | setString(id,"file_" + String(modcount.increase_get(context))); 118 | addString(msg, "reference", getString(id)); 119 | addString(msg, "fileName", fileName); 120 | addReal(msg, "tx", tx); 121 | addReal(msg, "ty", ty); 122 | addReal(msg, "tz", tz); 123 | sendMessage(conn, msg); 124 | end loadFromFile; 125 | 126 | 127 | function createSphere 128 | input Connection conn; 129 | input Context context; 130 | input Real size; 131 | input Id id; 132 | protected 133 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_sphere"); 134 | algorithm 135 | setString(id,"sphere_" + String(modcount.increase_get(context))); 136 | addString(msg, "reference", getString(id)); 137 | addReal(msg, "size", size); 138 | sendMessage(conn, msg); 139 | end createSphere; 140 | 141 | 142 | function createCylinder 143 | input Connection conn; 144 | input Context context; 145 | input Real height; 146 | input Real diameter; 147 | input Id id; 148 | protected 149 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_cylinder"); 150 | algorithm 151 | setString(id,"cylinder_" + String(modcount.increase_get(context))); 152 | addString(msg, "reference", getString(id)); 153 | addReal(msg, "height", height); 154 | addReal(msg, "diameter", diameter); 155 | sendMessage(conn, msg); 156 | end createCylinder; 157 | 158 | 159 | function createCylinderAt 160 | input Connection conn; 161 | input Context context; 162 | input Real height; 163 | input Real diameter; 164 | input Real x,y,z; 165 | input Id id; 166 | protected 167 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_cylinder"); 168 | algorithm 169 | setString(id,"cylinder_" + String(modcount.increase_get(context))); 170 | addString(msg, "reference", getString(id)); 171 | addReal(msg, "height", height); 172 | addReal(msg, "diameter", diameter); 173 | addReal(msg, "x", x); 174 | addReal(msg, "y", y); 175 | addReal(msg, "z", z); 176 | sendMessage(conn, msg); 177 | end createCylinderAt; 178 | 179 | 180 | function createCone 181 | input Connection conn; 182 | input Context context; 183 | input Real height; 184 | input Real diameter; 185 | input Id id; 186 | protected 187 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_cone"); 188 | algorithm 189 | setString(id,"cone_" + String(modcount.increase_get(context))); 190 | addString(msg, "reference", getString(id)); 191 | addReal(msg, "height", height); 192 | addReal(msg, "diameter", diameter); 193 | sendMessage(conn, msg); 194 | end createCone; 195 | 196 | 197 | function createConeAt 198 | input Connection conn; 199 | input Context context; 200 | input Real height; 201 | input Real diameter; 202 | input Real x,y,z; 203 | input Id id; 204 | protected 205 | Message msg = Message(TARGET, OBJECT, INTERFACE, "make_cone"); 206 | algorithm 207 | setString(id,"cone_" + String(modcount.increase_get(context))); 208 | addString(msg, "reference", getString(id)); 209 | addReal(msg, "height", height); 210 | addReal(msg, "diameter", diameter); 211 | addReal(msg, "x", x); 212 | addReal(msg, "y", y); 213 | addReal(msg, "z", z); 214 | sendMessage(conn, msg); 215 | end createConeAt; 216 | 217 | 218 | function moveTo 219 | input Connection conn; 220 | input Context context; 221 | input Id id; 222 | input Real p[3]; 223 | input Real t; 224 | output String r; 225 | protected 226 | Message msg = Message(TARGET, OBJECT, INTERFACE, "move_to"); 227 | algorithm 228 | addString(msg, "reference", getString(id)); 229 | addReal(msg, "x", p[1]); 230 | addReal(msg, "y", p[2]); 231 | addReal(msg, "z", p[3]); 232 | addReal(msg, "t", t); 233 | r := sendMessage(conn, msg); 234 | end moveTo; 235 | 236 | 237 | function moveZ 238 | input Connection conn; 239 | input Context context; 240 | input Id id; 241 | input Real z; 242 | input Real t; 243 | output String r; 244 | protected 245 | Message msg = Message(TARGET, OBJECT, INTERFACE, "move_to"); 246 | algorithm 247 | addString(msg, "reference", getString(id)); 248 | addReal(msg, "z", z); 249 | addReal(msg, "t", t); 250 | r := sendMessage(conn, msg); 251 | end moveZ; 252 | 253 | 254 | function scale 255 | input Connection conn; 256 | input Context context; 257 | input Id id; 258 | input Real x,y,z; 259 | input Real t; 260 | output String r; 261 | protected 262 | Message msg = Message(TARGET, OBJECT, INTERFACE, "scale"); 263 | algorithm 264 | addString(msg, "reference", getString(id)); 265 | addReal(msg, "x", x); 266 | addReal(msg, "y", y); 267 | addReal(msg, "z", z); 268 | addReal(msg, "t", t); 269 | r := sendMessage(conn, msg); 270 | end scale; 271 | 272 | 273 | function scaleZ 274 | input Connection conn; 275 | input Context context; 276 | input Id id; 277 | input Real z; 278 | input Real t; 279 | output String r; 280 | protected 281 | Message msg = Message(TARGET, OBJECT, INTERFACE, "scale"); 282 | algorithm 283 | addString(msg, "reference", getString(id)); 284 | addReal(msg, "z", z); 285 | addReal(msg, "t", t); 286 | r := sendMessage(conn, msg); 287 | end scaleZ; 288 | 289 | 290 | function setAmbientColor 291 | input Connection conn; 292 | input Context context; 293 | input Id id; 294 | input Real r,g,b,a; 295 | input Real t; 296 | output String res; 297 | protected 298 | Message msg = Message(TARGET, OBJECT, INTERFACE, "set_ambient_color"); 299 | algorithm 300 | addString(msg, "reference", getString(id)); 301 | addReal(msg, "r", r); 302 | addReal(msg, "g", g); 303 | addReal(msg, "b", b); 304 | addReal(msg, "a", a); 305 | addReal(msg, "t", t); 306 | res := sendMessage(conn, msg); 307 | end setAmbientColor; 308 | 309 | 310 | function setDiffuseColor 311 | input Connection conn; 312 | input Context context; 313 | input Id id; 314 | input Real r,g,b,a; 315 | input Real t; 316 | output String res; 317 | protected 318 | Message msg = Message(TARGET, OBJECT, INTERFACE, "set_diffuse_color"); 319 | algorithm 320 | addString(msg, "reference", getString(id)); 321 | addReal(msg, "r", r); 322 | addReal(msg, "g", g); 323 | addReal(msg, "b", b); 324 | addReal(msg, "a", a); 325 | addReal(msg, "t", t); 326 | res := sendMessage(conn, msg); 327 | end setDiffuseColor; 328 | 329 | 330 | function setSpecularColor 331 | input Connection conn; 332 | input Context context; 333 | input Id id; 334 | input Real r,g,b,a; 335 | input Real t; 336 | output String res; 337 | protected 338 | Message msg = Message(TARGET, OBJECT, INTERFACE, "set_specular_color"); 339 | algorithm 340 | addString(msg, "reference", getString(id)); 341 | addReal(msg, "r", r); 342 | addReal(msg, "g", g); 343 | addReal(msg, "b", b); 344 | addReal(msg, "a", a); 345 | addReal(msg, "t", t); 346 | res := sendMessage(conn, msg); 347 | end setSpecularColor; 348 | 349 | 350 | function setMatProperty 351 | input Connection conn; 352 | input Context context; 353 | input Id id; 354 | input String property; 355 | input Real value; 356 | input Real t; 357 | output String res; 358 | protected 359 | Message msg = Message(TARGET, OBJECT, INTERFACE, "set_material_property"); 360 | algorithm 361 | addString(msg, "reference", getString(id)); 362 | addString(msg, "prop", property); 363 | addReal(msg, "value", value); 364 | addReal(msg, "t", t); 365 | res := sendMessage(conn, msg); 366 | end setMatProperty; 367 | 368 | 369 | function loadSceneFromFile 370 | input Connection conn; 371 | input Context context; 372 | input String fileName; 373 | output String res; 374 | protected 375 | Message msg = Message(TARGET, OBJECT, INTERFACE, "load_scene"); 376 | algorithm 377 | addString(msg, "filepath", fileName); 378 | res := sendMessage(conn, msg); 379 | end loadSceneFromFile; 380 | 381 | 382 | function rotate 383 | input Connection conn; 384 | input Context context; 385 | input Id id; 386 | input Real[3,3] R; 387 | input Real t; 388 | output String r; 389 | protected 390 | Message msg = Message(TARGET, OBJECT, INTERFACE, "rotate"); 391 | algorithm 392 | addString(msg, "reference", getString(id)); 393 | 394 | /* arrays not yet supported by dbus layer */ 395 | for i in 1:3 loop 396 | for j in 1:3 loop 397 | addReal(msg, "R_" + String(i) + "_" + String(j), R[i,j]); 398 | end for; 399 | end for; 400 | 401 | addReal(msg, "t", t); 402 | r := sendMessage(conn, msg); 403 | end rotate; 404 | 405 | 406 | function stop 407 | input Connection conn; 408 | input Context context; 409 | output String r; 410 | protected 411 | Message msg = Message(TARGET, OBJECT, INTERFACE, "stop"); 412 | algorithm 413 | r := sendMessage(conn, msg); 414 | end stop; 415 | 416 | 417 | partial model PartialShape 418 | "Different visual shapes with variable size; all data have to be set as modifiers" 419 | extends 420 | Modelica.Utilities.Internal.PartialModelicaServices.Animation.PartialShape; 421 | 422 | import Bus = ModelicaServices.modbus; 423 | import ModelicaServices.modcount; 424 | import Id = ModelicaServices.modcount.HeapString; 425 | import Modelica.Mechanics.MultiBody.Frames; 426 | 427 | function shapeDescrTo3D 428 | input Connection conn; 429 | input Context context; 430 | input String descr; 431 | input Real length, width, height; 432 | input Real[3] at; 433 | input Real extra; 434 | input Id id; 435 | algorithm 436 | 437 | if (descr == "box") then 438 | createBoxAt(conn, context, width, height, length, at[1], at[2], at[3], id); 439 | elseif (descr == "cone") then 440 | createConeAt(conn, context, length, width, at[1], at[2], at[3], id); 441 | elseif (descr == "sphere") then 442 | createSphere(conn, context, length, id); 443 | elseif (descr == "cylinder") then 444 | createCylinderAt(conn, context, length, width, at[1], at[2], at[3], id); 445 | elseif (descr == "pipecylinder") then 446 | if (Modelica.Math.isEqual(extra, 0.0)) then 447 | createCylinderAt(conn, context, length, width, at[1], at[2], at[3], id); 448 | else 449 | // not yet supported 450 | Modelica.Utilities.Streams.print("Error: Visualization of pipecylinders has not been implemented yet!"); 451 | setString(id,"UNKNOWN"); 452 | end if; 453 | elseif (descr == "pipe") then 454 | if (Modelica.Math.isEqual(extra, 0.0)) then 455 | createCylinderAt(conn, context, length, width, at[1], at[2], at[3], id); 456 | else 457 | // not yet supported 458 | Modelica.Utilities.Streams.print("Error: Visualization of pipes has not been implemented yet!"); 459 | setString(id,"UNKNOWN"); 460 | end if; 461 | elseif (descr == "beam") then 462 | // not yet supported 463 | Modelica.Utilities.Streams.print("Error: Visualization of beams has not been implemented yet!"); 464 | setString(id,"UNKNOWN"); 465 | elseif (descr == "gearwheel") then 466 | // not yet supported 467 | Modelica.Utilities.Streams.print("Error: Visualization of gearwheels has not been implemented yet!"); 468 | setString(id,"UNKNOWN"); 469 | elseif (descr == "spring") then 470 | // not yet supported 471 | Modelica.Utilities.Streams.print("Error: Visualization of springs has not been implemented yet!"); 472 | setString(id,"UNKNOWN"); 473 | else 474 | // assume it is a filename 475 | loadFromFile(conn, context, Modelica.Utilities.Files.fullPathName(ModelicaServices.ExternalReferences.loadResource(descr)), at[1], at[2], at[3], id); 476 | end if; 477 | 478 | end shapeDescrTo3D; 479 | 480 | outer Controller m3d_control; 481 | 482 | Id id = Id(""); 483 | Id mat = Id(""); 484 | modcount.Context initContext = modcount.Context(); 485 | String res; 486 | 487 | discrete Real[3] pos; 488 | discrete Real[3,3] oldT; 489 | discrete Boolean moved; 490 | discrete Boolean rotated; 491 | // disable initial equation for now, since there is some bug in initial residuals 492 | //initial equation 493 | // pre(oldT) = R.T; 494 | // pre(pos) = r + Frames.resolve1(R, r_shape); 495 | algorithm 496 | when m3d_control.send and modcount.get(initContext) == 1 then 497 | // check for rotation 498 | rotated := not Modelica.Math.Matrices.isEqual(R.T, oldT); 499 | if noEvent(rotated) then 500 | res := rotate(m3d_control.conn, m3d_control.context, id, R.T, time); 501 | end if; 502 | oldT := R.T; 503 | 504 | // check for translation 505 | pos := r + Frames.resolve1(R, r_shape); 506 | moved := not Modelica.Math.Vectors.isEqual(pos, pre(pos)); 507 | if noEvent(moved) then 508 | res := moveTo(m3d_control.conn, m3d_control.context, id, pos, time); 509 | end if; 510 | 511 | end when; 512 | 513 | if modcount.get(initContext) <> 1 then 514 | 515 | Modelica.Utilities.Streams.print( "SHAPE " + getString(id) + " " + shapeType); 516 | Modelica.Utilities.Streams.print( "length = " + String(length)); 517 | Modelica.Utilities.Streams.print( "width = " + String(width)); 518 | Modelica.Utilities.Streams.print( "height = " + String(height)); 519 | 520 | 521 | shapeDescrTo3D(m3d_control.conn, m3d_control.context, shapeType, length, width, height, lengthDirection, extra, id); 522 | createMaterial(m3d_control.conn, m3d_control.context, mat); 523 | setAmbientColor(m3d_control.conn, m3d_control.context, mat, color[1] / 255, color[2] / 255, color[3] / 255, 1.0, time); 524 | setSpecularColor(m3d_control.conn, m3d_control.context, mat, specularCoefficient * (color[1] / 255), 525 | specularCoefficient * color[2] / 255, specularCoefficient * color[3] / 255, 1.0, time); 526 | 527 | applyMaterial(m3d_control.conn, m3d_control.context, id, mat); 528 | modcount.set(initContext, 1); 529 | end if; 530 | 531 | 532 | 533 | 534 | annotation ( 535 | Icon(coordinateSystem( 536 | preserveAspectRatio=true, 537 | extent={{-100,-100},{100,100}}, 538 | grid={2,2}), graphics={ 539 | Rectangle( 540 | extent={{-100,-100},{80,60}}, 541 | lineColor={0,0,255}, 542 | fillColor={255,255,255}, 543 | fillPattern=FillPattern.Solid), 544 | Polygon( 545 | points={{-100,60},{-80,100},{100,100},{80,60},{-100,60}}, 546 | lineColor={0,0,255}, 547 | fillColor={192,192,192}, 548 | fillPattern=FillPattern.Solid), 549 | Polygon( 550 | points={{100,100},{100,-60},{80,-100},{80,60},{100,100}}, 551 | lineColor={0,0,255}, 552 | fillColor={160,160,164}, 553 | fillPattern=FillPattern.Solid), 554 | Text( 555 | extent={{-100,-100},{80,60}}, 556 | lineColor={0,0,0}, 557 | textString="%shapeType"), 558 | Text( 559 | extent={{-132,160},{128,100}}, 560 | textString="%name", 561 | lineColor={0,0,255})}), 562 | Documentation(info=" 563 | 564 |

565 | This model is documented at 566 | Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape. 567 |

568 | 569 | 570 | ")); 571 | end PartialShape; 572 | end Modelica3D; 573 | -------------------------------------------------------------------------------- /lib/mod3d/src/modelica/Modelica3D 3.2.1/required changes.txt: -------------------------------------------------------------------------------- 1 | To use Modelica3D with Modelica 3.2.1, copy this package.mo to ModelicaServices/Modelica3D/package.mo along with modbus and modcount (as in the old version) 2 | 3 | Additionally, the model Shape 4 | 5 | {{{ 6 | package Animation "Models and functions for 3-dim. animation" 7 | extends Modelica.Icons.Package; 8 | model Shape 9 | "Different visual shapes with variable size; all data have to be set as modifiers (see info layer)" 10 | extends 11 | Modelica.Utilities.Internal.PartialModelicaServices.Animation.PartialShape; 12 | }}} 13 | 14 | has to be extended from Modelica3D.PartialShape, i.e. it becomes 15 | 16 | {{{ 17 | package Animation "Models and functions for 3-dim. animation" 18 | extends Modelica.Icons.Package; 19 | model Shape 20 | "Different visual shapes with variable size; all data have to be set as modifiers (see info layer)" 21 | extends 22 | Modelica.Utilities.Internal.PartialModelicaServices.Animation.PartialShape; 23 | extends 24 | ModelicaServices.Modelica3D.PartialShape; 25 | }}} 26 | -------------------------------------------------------------------------------- /lib/mod3d/src/modelica/package.mo: -------------------------------------------------------------------------------- 1 | within ; 2 | package ModelicaServices "ModelicaServices (OpenModelica implementation + Modelica3D hooks) - Models and functions used in the Modelica Standard Library requiring a tool specific implementation" 3 | extends Modelica.Icons.Package; 4 | constant String target="OpenModelica" 5 | "Target of this ModelicaServices implementation"; 6 | 7 | 8 | package UsersGuide "User's Guide" 9 | extends Modelica.Icons.Information; 10 | class ModelicaLicense2 "Modelica License 2" 11 | extends Modelica.Icons.Information; 12 | annotation (Documentation(info=" 13 | 14 | The Modelica License 2 15 | 26 | 27 | 28 |

All files in this directory (Modelica) and in all 29 | subdirectories are licensed by the Modelica Association under the 30 | Modelica License 2.

31 | 32 |

Licensor:
33 | Modelica Association
34 | (Ideella Föreningar 822003-8858 in Linköping)
35 | c/o PELAB, IDA, Linköpings Universitet
36 | S-58183 Linköping
37 | Sweden
38 | email: Board@Modelica.org
39 | web: https://www.Modelica.org

40 | 41 |

Copyright notices of the files:
42 | Copyright © 1998-2013, DLR, Dassault Systèmes AB. 43 |

44 | 45 |

46 | The Modelica License 2
47 | Frequently Asked Questions
48 |

49 | 50 |
51 | 52 |

The Modelica License 2

53 | 54 |

55 | Preamble. The goal of this license is that Modelica related 56 | model libraries, software, images, documents, data files etc. can be 57 | used freely in the original or a modified form, in open source and in 58 | commercial environments (as long as the license conditions below are 59 | fulfilled, in particular sections 2c) and 2d). The Original Work is 60 | provided free of charge and the use is completely at your own risk. 61 | Developers of free Modelica packages are encouraged to utilize this 62 | license for their work.

63 | 64 |

65 | The Modelica License applies to any Original Work that contains the 66 | following licensing notice adjacent to the copyright notice(s) for 67 | this Original Work:

68 | 69 |

Licensed by the Modelica Association under the Modelica License 2

70 | 71 |

1. Definitions.

72 |
    73 |
  1. “License” is this Modelica License.
  2. 74 | 75 |
  3. “Original Work” is any work of authorship, including 76 | software, images, documents, data files, that contains the above 77 | licensing notice or that is packed together with a licensing notice 78 | referencing it.
  4. 79 | 80 |
  5. “Licensor” is the provider of the Original Work who has 81 | placed this licensing notice adjacent to the copyright notice(s) for 82 | the Original Work. The Original Work is either directly provided by 83 | the owner of the Original Work, or by a licensee of the owner.
  6. 84 | 85 |
  7. “Derivative Work” is any modification of the Original 86 | Work which represents, as a whole, an original work of authorship. 87 | For the matter of clarity and as examples: 88 | 89 |
      90 |
    1. Derivative Work shall not include work that remains separable from 91 | the Original Work, as well as merely extracting a part of the 92 | Original Work without modifying it.
    2. 93 | 94 |
    3. Derivative Work shall not include (a) fixing of errors and/or (b) 95 | adding vendor specific Modelica annotations and/or (c) using a 96 | subset of the classes of a Modelica package, and/or (d) using a 97 | different representation, e.g., a binary representation.
    4. 98 | 99 |
    5. Derivative Work shall include classes that are copied from the 100 | Original Work where declarations, equations or the documentation 101 | are modified.
    6. 102 | 103 |
    7. Derivative Work shall include executables to simulate the models 104 | that are generated by a Modelica translator based on the Original 105 | Work (of a Modelica package).
    8. 106 |
    107 | 108 |
  8. “Modified Work” is any modification of the Original Work 109 | with the following exceptions: (a) fixing of errors and/or (b) 110 | adding vendor specific Modelica annotations and/or (c) using a 111 | subset of the classes of a Modelica package, and/or (d) using a 112 | different representation, e.g., a binary representation.
  9. 113 | 114 |
  10. "Source Code" means the preferred form of the Original 115 | Work for making modifications to it and all available documentation 116 | describing how to modify the Original Work.
  11. 117 | 118 |
  12. “You” means an individual or a legal entity exercising 119 | rights under, and complying with all of the terms of, this License.
  13. 120 | 121 |
  14. “Modelica package” means any Modelica library that is 122 | defined with the “package <Name> ... end <Name>;” Modelica language element.
  15. 123 | 124 |
125 | 126 |

127 | 2. Grant of Copyright License. Licensor grants You a 128 | worldwide, royalty-free, non-exclusive, sublicensable license, for 129 | the duration of the copyright, to do the following:

130 | 131 |
    132 |
  1. 133 | To reproduce the Original Work in copies, either alone or as part of 134 | a collection.

  2. 135 |
  3. 136 | To create Derivative Works according to Section 1d) of this License.

  4. 137 |
  5. 138 | To distribute or communicate to the public copies of the Original 139 | Work or a Derivative Work under this License. No 140 | fee, neither as a copyright-license fee, nor as a selling fee for 141 | the copy as such may be charged under this License. Furthermore, a 142 | verbatim copy of this License must be included in any copy of the 143 | Original Work or a Derivative Work under this License.
    144 | For the matter of clarity, it is permitted A) to distribute or 145 | communicate such copies as part of a (possible commercial) 146 | collection where other parts are provided under different licenses 147 | and a license fee is charged for the other parts only and B) to 148 | charge for mere printing and shipping costs.

  6. 149 |
  7. 150 | To distribute or communicate to the public copies of a Derivative 151 | Work, alternatively to Section 2c), under any other license 152 | of your choice, especially also under a license for 153 | commercial/proprietary software, as long as You comply with Sections 154 | 3, 4 and 8 below.
    For the matter of clarity, no 155 | restrictions regarding fees, either as to a copyright-license fee or 156 | as to a selling fee for the copy as such apply.

  8. 157 |
  9. 158 | To perform the Original Work publicly.

  10. 159 |
  11. 160 | To display the Original Work publicly.

  12. 161 |
162 | 163 |

164 | 3. Acceptance. Any use of the Original Work or a 165 | Derivative Work, or any action according to either Section 2a) to 2f) 166 | above constitutes Your acceptance of this License.

167 | 168 |

169 | 4. Designation of Derivative Works and of Modified Works. 170 | The identifying designation of Derivative Work and of Modified 171 | Work must be different to the corresponding identifying designation 172 | of the Original Work. This means especially that the (root-level) 173 | name of a Modelica package under this license must be changed if the 174 | package is modified (besides fixing of errors, adding vendor specific 175 | Modelica annotations, using a subset of the classes of a Modelica 176 | package, or using another representation, e.g. a binary 177 | representation).

178 | 179 |

180 | 5. Grant of Patent License. 181 | Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, 182 | under patent claims owned by the Licensor or licensed to the Licensor by 183 | the owners of the Original Work that are embodied in the Original Work 184 | as furnished by the Licensor, for the duration of the patents, 185 | to make, use, sell, offer for sale, have made, and import the Original Work 186 | and Derivative Works under the conditions as given in Section 2. 187 | For the matter of clarity, the license regarding Derivative Works covers 188 | patent claims to the extent as they are embodied in the Original Work only.

189 | 190 |

191 | 6. Provision of Source Code. Licensor agrees to provide 192 | You with a copy of the Source Code of the Original Work but reserves 193 | the right to decide freely on the manner of how the Original Work is 194 | provided.
195 |       For the matter of clarity, Licensor might provide only a binary 196 | representation of the Original Work. In that case, You may (a) either 197 | reproduce the Source Code from the binary representation if this is 198 | possible (e.g., by performing a copy of an encrypted Modelica 199 | package, if encryption allows the copy operation) or (b) request the 200 | Source Code from the Licensor who will provide it to You.

201 | 202 |

203 | 7. Exclusions from License Grant. Neither the names of 204 | Licensor, nor the names of any contributors to the Original Work, nor 205 | any of their trademarks or service marks, may be used to endorse or 206 | promote products derived from this Original Work without express 207 | prior permission of the Licensor. Except as otherwise expressly 208 | stated in this License and in particular in Sections 2 and 5, nothing 209 | in this License grants any license to Licensor’s trademarks, 210 | copyrights, patents, trade secrets or any other intellectual 211 | property, and no patent license is granted to make, use, sell, offer 212 | for sale, have made, or import embodiments of any patent claims.
213 |       No license is granted to the trademarks of 214 | Licensor even if such trademarks are included in the Original Work, 215 | except as expressly stated in this License. Nothing in this License 216 | shall be interpreted to prohibit Licensor from licensing under terms 217 | different from this License any Original Work that Licensor otherwise 218 | would have a right to license.

219 | 220 |

221 | 8. Attribution Rights. You must retain in the Source 222 | Code of the Original Work and of any Derivative Works that You 223 | create, all author, copyright, patent, or trademark notices, as well 224 | as any descriptive text identified therein as an "Attribution 225 | Notice". The same applies to the licensing notice of this 226 | License in the Original Work. For the matter of clarity, “author 227 | notice” means the notice that identifies the original 228 | author(s).
229 |       You must cause the Source Code for any Derivative 230 | Works that You create to carry a prominent Attribution Notice 231 | reasonably calculated to inform recipients that You have modified the 232 | Original Work.
233 |       In case the Original Work or Derivative Work is not provided in 234 | Source Code, the Attribution Notices shall be appropriately 235 | displayed, e.g., in the documentation of the Derivative Work.

236 | 237 |

9. Disclaimer 238 | of Warranty.
The Original Work is provided under this 239 | License on an "as is" basis and without warranty, either 240 | express or implied, including, without limitation, the warranties of 241 | non-infringement, merchantability or fitness for a particular 242 | purpose. The entire risk as to the quality of the Original Work is 243 | with You. This disclaimer of warranty constitutes an 244 | essential part of this License. No license to the Original Work is 245 | granted by this License except under this disclaimer.

246 | 247 |

248 | 10. Limitation of Liability. Under no circumstances and 249 | under no legal theory, whether in tort (including negligence), 250 | contract, or otherwise, shall the Licensor, the owner or a licensee 251 | of the Original Work be liable to anyone for any direct, indirect, 252 | general, special, incidental, or consequential damages of any 253 | character arising as a result of this License or the use of the 254 | Original Work including, without limitation, damages for loss of 255 | goodwill, work stoppage, computer failure or malfunction, or any and 256 | all other commercial damages or losses. This limitation of liability 257 | shall not apply to the extent applicable law prohibits such 258 | limitation.

259 | 260 |

261 | 11. Termination. This License conditions your rights to 262 | undertake the activities listed in Section 2 and 5, including your 263 | right to create Derivative Works based upon the Original Work, and 264 | doing so without observing these terms and conditions is prohibited 265 | by copyright law and international treaty. Nothing in this License is 266 | intended to affect copyright exceptions and limitations. This License 267 | shall terminate immediately and You may no longer exercise any of the 268 | rights granted to You by this License upon your failure to observe 269 | the conditions of this license.

270 | 271 |

272 | 12. Termination for Patent Action. This License shall 273 | terminate automatically and You may no longer exercise any of the 274 | rights granted to You by this License as of the date You commence an 275 | action, including a cross-claim or counterclaim, against Licensor, 276 | any owners of the Original Work or any licensee alleging that the 277 | Original Work infringes a patent. This termination provision shall 278 | not apply for an action alleging patent infringement through 279 | combinations of the Original Work under combination with other 280 | software or hardware.

281 | 282 |

283 | 13. Jurisdiction. Any action or suit relating to this 284 | License may be brought only in the courts of a jurisdiction wherein 285 | the Licensor resides and under the laws of that jurisdiction 286 | excluding its conflict-of-law provisions. The application of the 287 | United Nations Convention on Contracts for the International Sale of 288 | Goods is expressly excluded. Any use of the Original Work outside the 289 | scope of this License or after its termination shall be subject to 290 | the requirements and penalties of copyright or patent law in the 291 | appropriate jurisdiction. This section shall survive the termination 292 | of this License.

293 | 294 |

295 | 14. Attorneys’ Fees. In any action to enforce the 296 | terms of this License or seeking damages relating thereto, the 297 | prevailing party shall be entitled to recover its costs and expenses, 298 | including, without limitation, reasonable attorneys' fees and costs 299 | incurred in connection with such action, including any appeal of such 300 | action. This section shall survive the termination of this License.

301 | 302 |

303 | 15. Miscellaneous. 304 |

305 |
    306 |
  1. If any 307 | provision of this License is held to be unenforceable, such 308 | provision shall be reformed only to the extent necessary to make it 309 | enforceable.
  2. 310 | 311 |
  3. No verbal 312 | ancillary agreements have been made. Changes and additions to this 313 | License must appear in writing to be valid. This also applies to 314 | changing the clause pertaining to written form.
  4. 315 | 316 |
  5. You may use the 317 | Original Work in all ways not otherwise restricted or conditioned by 318 | this License or by law, and Licensor promises not to interfere with 319 | or be responsible for such uses by You.
  6. 320 |
321 | 322 |
323 | 324 |
325 | Frequently Asked Questions
326 |

This 327 | section contains questions/answer to users and/or distributors of 328 | Modelica packages and/or documents under Modelica License 2. Note, 329 | the answers to the questions below are not a legal interpretation of 330 | the Modelica License 2. In case of a conflict, the language of the 331 | license shall prevail.

332 | 333 |
Using or Distributing a Modelica Package under the Modelica License 2
334 | 335 |

What are the main 336 | differences to the previous version of the Modelica License?

337 |
    338 |
  1. 339 | Modelica License 1 is unclear whether the licensed Modelica package 340 | can be distributed under a different license. Version 2 explicitly 341 | allows that “Derivative Work” can be distributed under 342 | any license of Your choice, see examples in Section 1d) as to what 343 | qualifies as Derivative Work (so, version 2 is clearer).

    344 |
  2. 345 | If You modify a Modelica package under Modelica License 2 (besides 346 | fixing of errors, adding vendor specific Modelica annotations, using 347 | a subset of the classes of a Modelica package, or using another 348 | representation, e.g., a binary representation), you must rename the 349 | root-level name of the package for your distribution. In version 1 350 | you could keep the name (so, version 2 is more restrictive). The 351 | reason of this restriction is to reduce the risk that Modelica 352 | packages are available that have identical names, but different 353 | functionality.

    354 |
  3. 355 | Modelica License 1 states that “It is not allowed to charge a 356 | fee for the original version or a modified version of the software, 357 | besides a reasonable fee for distribution and support”. 358 | Version 2 has a similar intention for all Original Work under 359 | Modelica License 2 (to remain free of charge and open source) 360 | but states this more clearly as “No fee, neither as a 361 | copyright-license fee, nor as a selling fee for the copy as such may 362 | be charged”. Contrary to version 1, Modelica License 2 has no 363 | restrictions on fees for Derivative Work that is provided under a 364 | different license (so, version 2 is clearer and has fewer 365 | restrictions).

    366 |
  4. 367 | Modelica License 2 introduces several useful provisions for the 368 | licensee (articles 5, 6, 12), and for the licensor (articles 7, 12, 369 | 13, 14) that have no counter part in version 1.

    370 |
  5. 371 | Modelica License 2 can be applied to all type of work, including 372 | documents, images and data files, contrary to version 1 that was 373 | dedicated for software only (so, version 2 is more general).

    374 |
375 | 376 |

Can I distribute a 377 | Modelica package (under Modelica License 2) as part of my commercial 378 | Modelica modeling and simulation environment?

379 |

Yes, 380 | according to Section 2c). However, you are not allowed to charge a 381 | fee for this part of your environment. Of course, you can charge for 382 | your part of the environment. 383 |

384 | 385 |

Can I distribute a 386 | Modelica package (under Modelica License 2) under a different 387 | license?

388 |

No. 389 | The license of an unmodified Modelica package cannot be changed 390 | according to Sections 2c) and 2d). This means that you cannot sell 391 | copies of it, any distribution has to be free of charge.

392 | 393 |

Can I distribute a 394 | Modelica package (under Modelica License 2) under a different license 395 | when I first encrypt the package?

396 |

No. 397 | Merely encrypting a package does not qualify for Derivative Work and 398 | therefore the encrypted package has to stay under Modelica License 2.

399 | 400 |

Can I distribute a 401 | Modelica package (under Modelica License 2) under a different license 402 | when I first add classes to the package?

403 |

No. 404 | The package itself remains unmodified, i.e., it is Original Work, and 405 | therefore the license for this part must remain under Modelica 406 | License 2. The newly added classes can be, however, under a different 407 | license. 408 |

409 | 410 |

Can 411 | I copy a class out of a Modelica package (under Modelica License 2) 412 | and include it unmodified in a Modelica package 413 | under a commercial/proprietary license?

414 |

No, 415 | according to article 2c). However, you can include model, block, 416 | function, package, record and connector classes in your Modelica 417 | package under Modelica License 2. This means that your 418 | Modelica package could be under a commercial/proprietary license, but 419 | one or more classes of it are under Modelica License 2.
Note, a 420 | “type” class (e.g., type Angle = Real(unit=”rad”)) 421 | can be copied and included unmodified under a commercial/proprietary 422 | license (for details, see the next question).

423 | 424 |

Can 425 | I copy a type class or part of a model, block, 426 | function, record, connector class, out of a Modelica package (under 427 | Modelica License 2) and include it modified or unmodified in a 428 | Modelica package under a commercial/proprietary 429 | license

430 |

Yes, 431 | according to article 2d), since this will in the end usually qualify 432 | as Derivative Work. The reasoning is the following: A type class or 433 | part of another class (e.g., an equation, a declaration, part of a 434 | class description) cannot be utilized “by its own”. In 435 | order to make this “usable”, you have to add additional 436 | code in order that the class can be utilized. This is therefore 437 | usually Derivative Work and Derivative Work can be provided under a 438 | different license. Note, this only holds, if the additional code 439 | introduced is sufficient to qualify for Derivative Work. Merely, just 440 | copying a class and changing, say, one character in the documentation 441 | of this class would be no Derivative Work and therefore the copied 442 | code would have to stay under Modelica License 2.

443 | 444 |

Can 445 | I copy a class out of a Modelica package (under Modelica License 2) 446 | and include it in modified form in a 447 | commercial/proprietary Modelica package?

448 |

Yes. 449 | If the modification can be seen as a “Derivative Work”, 450 | you can place it under your commercial/proprietary license. If the 451 | modification does not qualify as “Derivative Work” (e.g., 452 | bug fixes, vendor specific annotations), it must remain under 453 | Modelica License 2. This means that your Modelica package could be 454 | under a commercial/proprietary license, but one or more parts of it 455 | are under Modelica License 2.

456 | 457 |

Can I distribute a 458 | “save total model” under my commercial/proprietary 459 | license, even if classes under Modelica License 2 are included?

460 |

Your 461 | classes of the “save total model” can be distributed 462 | under your commercial/proprietary license, but the classes under 463 | Modelica License 2 must remain under Modelica License 2. This means 464 | you can distribute a “save total model”, but some parts 465 | might be under Modelica License 2.

466 | 467 |

Can I distribute a 468 | Modelica package (under Modelica License 2) in encrypted form?

469 |

Yes. 470 | Note, if the encryption does not allow “copying” of 471 | classes (in to unencrypted Modelica source code), you have to send 472 | the Modelica source code of this package to your customer, if he/she 473 | wishes it, according to article 6.

474 | 475 |

Can I distribute an 476 | executable under my commercial/proprietary license, if the model from 477 | which the executable is generated uses models from a Modelica package 478 | under Modelica License 2?

479 |

Yes, 480 | according to article 2d), since this is seen as Derivative Work. The 481 | reasoning is the following: An executable allows the simulation of a 482 | concrete model, whereas models from a Modelica package (without 483 | pre-processing, translation, tool run-time library) are not able to 484 | be simulated without tool support. By the processing of the tool and 485 | by its run-time libraries, significant new functionality is added (a 486 | model can be simulated whereas previously it could not be simulated) 487 | and functionality available in the package is removed (e.g., to build 488 | up a new model by dragging components of the package is no longer 489 | possible with the executable).

490 | 491 |

Is my modification to 492 | a Modelica package (under Modelica License 2) a Derivative Work?

493 |

It 494 | is not possible to give a general answer to it. To be regarded as "an 495 | original work of authorship", a derivative work must be 496 | different enough from the original or must contain a substantial 497 | amount of new material. Making minor changes or additions of little 498 | substance to a preexisting work will not qualify the work as a new 499 | version for such purposes. 500 |

501 | 502 |
Using or Distributing a Modelica Document under the Modelica License 2
503 | 504 |

This 505 | section is devoted especially for the following applications:

506 |
    507 |
  1. 508 | A Modelica tool extracts information out of a Modelica package and 509 | presents the result in form of a “manual” for this 510 | package in, e.g., html, doc, or pdf format.

    511 |
  2. 512 | The Modelica language specification is a document defining the 513 | Modelica language. It will be licensed under Modelica License 2.

    514 |
  3. 515 | Someone writes a book about the Modelica language and/or Modelica 516 | packages and uses information which is available in the Modelica 517 | language specification and/or the corresponding Modelica package.

    518 |
519 | 520 |

Can I sell a manual 521 | that was basically derived by extracting information automatically 522 | from a Modelica package under Modelica License 2 (e.g., a “reference 523 | guide” of the Modelica Standard Library):

524 |

Yes. 525 | Extracting information from a Modelica package, and providing it in a 526 | human readable, suitable format, like html, doc or pdf format, where 527 | the content is significantly modified (e.g. tables with interface 528 | information are constructed from the declarations of the public 529 | variables) qualifies as Derivative Work and there are no restrictions 530 | to charge a fee for Derivative Work under alternative 2d).

531 | 532 |

Can 533 | I copy a text passage out of a Modelica document (under Modelica 534 | License 2) and use it unmodified in my document 535 | (e.g. the Modelica syntax description in the Modelica Specification)?

536 |

Yes. 537 | In case you distribute your document, the copied parts are still 538 | under Modelica License 2 and you are not allowed to charge a license 539 | fee for this part. You can, of course, charge a fee for the rest of 540 | your document.

541 | 542 |

Can 543 | I copy a text passage out of a Modelica document (under Modelica 544 | License 2) and use it in modified form in my 545 | document?

546 |

Yes, 547 | the creation of Derivative Works is allowed. In case the content is 548 | significantly modified this qualifies as Derivative Work and there 549 | are no restrictions to charge a fee for Derivative Work under 550 | alternative 2d).

551 | 552 |

Can I sell a printed 553 | version of a Modelica document (under Modelica License 2), e.g., the 554 | Modelica Language Specification?

555 |

No, 556 | if you are not the copyright-holder, since article 2c) does not allow 557 | a selling fee for a (in this case physical) copy. However, mere 558 | printing and shipping costs may be recovered.

559 | ")); 560 | end ModelicaLicense2; 561 | 562 | class ReleaseNotes "Release notes" 563 | extends Modelica.Icons.ReleaseNotes; 564 | annotation (Documentation(info=" 565 |

Version 3.2.1, 2012-12-05

566 | 567 |
    568 |
  • Version numbering adapted to the corresponding version number of 569 | package Modelica (= Modelica Standard Library).
  • 570 |
  • New function 571 | loadResource 572 | to determine the absolute, local file name from an URI path name. 573 |
  • 574 |
  • New String type with tool dependent choices 575 | SolverMethod 576 | to define the integration method to solve differential equations in a 577 | clocked discretized continuous-time partition. 578 |
  • 579 |
  • New package 580 | Machine 581 | to define the processor dependent constants as used in 582 | Modelica.Constants. 583 |
  • 584 |
585 | 586 | 587 |

Version 1.1, 2010-07-30

588 | 589 |
    590 |
  • New model Surface 591 | to describe movable, parameterized surfaces.
  • 592 |
  • New string constant ModelicaServices.target to define the 593 | target of the corresponding ModelicaServices implementation
  • 594 |
  • Package icons adapted to the icons of package Modelica, version 3.2.
  • 595 |
  • ModelicaServices library on the Modelica subversion server provided in three versions: 596 |
      597 |
    1. Default/ModelicaServices
      598 | (for tools that do not support 3-dim. visualization).
    2. 599 | 600 |
    3. Dymola/ModelicaServices
      601 | (a Dymola-specific implementation).
    4. 602 | 603 |
    5. DymolaAndDLRVisualization/ModelicaServices
      604 | (an implementation that uses the DLR Visualization library 605 | in combination with Dymola).
    6. 606 |
    607 |
  • 608 |
609 | 610 |

Version 1.0, 2009-06-21

611 | 612 |

613 | First version of the ModelicaServices library. 614 |

615 | ")); 616 | end ReleaseNotes; 617 | 618 | class Contact "Contact" 619 | extends Modelica.Icons.Contact; 620 | annotation (Documentation(info=" 621 |
Main Author:
622 | 623 | 624 | 625 | 634 | 635 |
626 | Martin Otter
627 | Deutsches Zentrum für Luft und Raumfahrt e.V. (DLR)
628 | Robotik und Mechatronik Zentrum (RMC)
629 | Institut für Systemdynamik und Regelungstechnik (SR)
630 | Postfach 1116
631 | D-82230 Wessling
632 | Germany
633 | email: Martin.Otter@dlr.de
636 | 637 |

Acknowledgements:

638 | 639 |

640 | The design of the Animation.Shape component is from Hilding Elmqvist, Dassault Systèmes AB. 641 |

642 | ")); 643 | 644 | end Contact; 645 | annotation (__Dymola_DocumentationClass=true); 646 | end UsersGuide; 647 | 648 | 649 | package Animation "Models and functions for 3-dim. animation" 650 | extends Modelica.Icons.Package; 651 | model Shape 652 | "Different visual shapes with variable size; all data have to be set as modifiers (see info layer)" 653 | extends Modelica.Utilities.Internal.PartialModelicaServices.Animation.PartialShape; 654 | extends ModelicaServices.Modelica3D.PartialShape; 655 | 656 | annotation (Icon(coordinateSystem( 657 | preserveAspectRatio=true, 658 | extent={{-100,-100},{100,100}}, 659 | grid={2,2}), graphics={Text( 660 | extent={{-150,-110},{150,-140}}, 661 | lineColor={0,0,0}, 662 | textString="default")}), Documentation(info=" 663 |

664 | The interface of this model is documented at 665 | Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape. 666 |

667 | 668 | ")); 669 | 670 | end Shape; 671 | 672 | model Surface 673 | "Animation of a moveable, parameterized surface; the surface characteristic is provided by a function" 674 | 675 | annotation (Documentation(info=" 676 |

677 | The interface of this model is documented at 678 | Modelica.Mechanics.MultiBody.Visualizers.Advanced.Surface.
679 | The interface of this model is defined at 680 | Modelica.Utilities.Internal.PartialModelicaServices.Animation.PartialSurface. 681 |

682 | 683 | ")); 684 | end Surface; 685 | end Animation; 686 | 687 | 688 | package ExternalReferences "Library of functions to access external resources" 689 | extends Modelica.Icons.Package; 690 | function loadResource 691 | "Return the absolute path name of a URI or local file name (in this default implementation URIs are not supported, but only local file names)" 692 | extends 693 | Modelica.Utilities.Internal.PartialModelicaServices.ExternalReferences.PartialLoadResource; 694 | algorithm 695 | fileReference:=OpenModelica.Scripting.uriToFilename(uri); 696 | 697 | annotation (Documentation(info=" 698 |

699 | The interface of this model is documented at 700 | Modelica.Utilities.Files.loadResource. 701 |

702 | ")); 703 | end loadResource; 704 | end ExternalReferences; 705 | 706 | 707 | package Machine 708 | // Machine dependent constants 709 | extends Modelica.Icons.Package; 710 | final constant Real eps=1.e-15 "Biggest number such that 1.0 + eps = 1.0"; 711 | final constant Real small=1.e-60 712 | "Smallest number such that small and -small are representable on the machine"; 713 | final constant Real inf=1.e+60 714 | "Biggest Real number such that inf and -inf are representable on the machine"; 715 | final constant Integer Integer_inf=OpenModelica.Internal.Architecture.integerMax() 716 | "Biggest Integer number such that Integer_inf and -Integer_inf are representable on the machine"; 717 | annotation (Documentation(info=" 718 |

719 | Package in which processor specific constants are defined that are needed 720 | by numerical algorithms. Typically these constants are not directly used, 721 | but indirectly via the alias definition in 722 | Modelica.Constants. 723 |

724 | ")); 725 | end Machine; 726 | 727 | 728 | package Types "Library of types with vendor specific choices" 729 | extends Modelica.Icons.Package; 730 | type SolverMethod = String 731 | "String defining the integration method to solve differential equations in a clocked discretized continuous-time partition" 732 | annotation (choices( 733 | choice="External" "Solver specified externally", 734 | choice="ExplicitEuler" "Explicit Euler method (order 1)", 735 | choice="ExplicitMidPoint2" "Explicit mid point rule (order 2)", 736 | choice="ExplicitRungeKutta4" "Explicit Runge-Kutta method (order 4)", 737 | choice="ImplicitEuler" "Implicit Euler method (order 1)", 738 | choice="ImplicitTrapezoid" "Implicit trapezoid rule (order 2)"), 739 | Documentation(info=" 740 |

741 | Type SolverMethod is a String type with menu choices to select the 742 | integration method to solve differential equations in a clocked discretized 743 | continuous-time partition. The choices are tool dependent. 744 | For details, see chapter 16.8.2 \"Solver Method\" in the Modelica Language 745 | Specification (version ≥ 3.3). 746 |

747 | ")); 748 | end Types; 749 | 750 | 751 | annotation ( 752 | Protection(access=Access.hide), 753 | preferredView="info", 754 | version="3.2.1 modelica3d", 755 | versionDate="2012-12-05", 756 | versionBuild=0, 757 | revisionId="$Id:: package.mo 6169 2013-03-30 17:25:09Z #$", 758 | uses(Modelica(version="3.2.1")), 759 | conversion( 760 | noneFromVersion="1.0", 761 | noneFromVersion="1.1", 762 | noneFromVersion="1.2"), 763 | Documentation(info=" 764 |

765 | This package contains a set of functions and models to be used in the 766 | Modelica Standard Library that requires a tool specific implementation. 767 | These are: 768 |

769 | 770 | 798 | 799 |

800 | This is the default implementation, if no tool-specific implementation is available. 801 | This ModelicaServices package provides only \"dummy\" models that do nothing. 802 |

803 | 804 |

805 | Licensed by DLR and Dassault Systèmes AB under the Modelica License 2
806 | Copyright © 2009-2013, DLR and Dassault Systèmes AB. 807 |

808 | 809 |

810 | This Modelica package is free software and the use is completely at your own risk; it can be redistributed and/or modified under the terms of the Modelica License 2. For license conditions (including the disclaimer of warranty) see Modelica.UsersGuide.ModelicaLicense2 or visit https://www.modelica.org/licenses/ModelicaLicense2. 811 |

812 | 813 | ")); 814 | end ModelicaServices; 815 | -------------------------------------------------------------------------------- /lib/modbus/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(DBUS REQUIRED) 2 | 3 | include_directories(${DBUS_INCLUDES} ${OMC_INCLUDES}) 4 | set(modbus_src "${CMAKE_SOURCE_DIR}/lib/modbus/src/") 5 | 6 | add_library(modbus "${modbus_src}/c/modbus.c") 7 | 8 | if(MSVC) 9 | set_source_files_properties("${modbus_src}/c/modbus.c" PROPERTIES LANGUAGE CXX) 10 | endif(MSVC) 11 | 12 | if (USE_OMC) 13 | # Modelica library to install 14 | install(DIRECTORY "${modbus_src}/modelica/modbus" 15 | DESTINATION "${OMC_MOD_LIB_DIR}/${MODELICA_SERVICES_LIBRARY}") 16 | 17 | # Install library header 18 | install(FILES "${modbus_src}/c/modbus.h" DESTINATION ${OMC_INCLUDE_DIR}) 19 | 20 | install(TARGETS modbus 21 | LIBRARY DESTINATION ${OMC_LIBRARY_DIR} 22 | ARCHIVE DESTINATION ${OMC_LIBRARY_DIR} 23 | ) 24 | endif(USE_OMC) 25 | -------------------------------------------------------------------------------- /lib/modbus/src/c/modbus.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #define DBUS_STATIC_BUILD /* In order to link against dbus static lib. */ 23 | #include 24 | #include 25 | #include 26 | 27 | #include "modbus.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" 31 | { 32 | #endif 33 | 34 | DBusError err; 35 | 36 | typedef struct modbus_message { 37 | DBusMessage* msg; 38 | DBusMessageIter args; 39 | DBusMessageIter dict; 40 | } ModbusMessage; 41 | 42 | void* modbus_acquire_session_bus(const char * client_name) { 43 | dbus_error_init(&err); 44 | 45 | /* taken from http://www.matthew.ath.cx/misc/dbus */ 46 | DBusConnection* conn = dbus_bus_get(DBUS_BUS_SESSION, &err); 47 | 48 | if (dbus_error_is_set(&err)) { 49 | fprintf(stderr, "Connection Error (%s)\n", err.message); 50 | dbus_error_free(&err); 51 | } 52 | 53 | if (NULL == conn) { 54 | exit(1); 55 | } 56 | 57 | // request a name on the bus 58 | int ret = dbus_bus_request_name(conn, client_name, 59 | DBUS_NAME_FLAG_REPLACE_EXISTING 60 | , &err); 61 | 62 | if (dbus_error_is_set(&err)) { 63 | fprintf(stderr, "Name Error (%s)\n", err.message); 64 | dbus_error_free(&err); 65 | } 66 | 67 | if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { 68 | exit(1); 69 | } 70 | 71 | return (void*)conn; 72 | } 73 | 74 | void modbus_release_bus(void* vconn) { 75 | DBusConnection* conn = (DBusConnection*)vconn; 76 | dbus_connection_unref(conn); 77 | } 78 | 79 | void* modbus_msg_alloc(const char *target, const char* object, const char *interface, const char* method) { 80 | ModbusMessage* message = (ModbusMessage*)malloc(sizeof(ModbusMessage)); 81 | 82 | message->msg = dbus_message_new_method_call(target, object, interface, method); 83 | if (NULL == message->msg) { 84 | fprintf(stderr, "Message Null\n"); 85 | exit(1); 86 | } 87 | 88 | dbus_message_iter_init_append(message->msg, &(message->args)); 89 | dbus_message_iter_open_container(&(message->args), DBUS_TYPE_ARRAY, 90 | DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING 91 | DBUS_TYPE_STRING_AS_STRING 92 | DBUS_TYPE_VARIANT_AS_STRING 93 | DBUS_DICT_ENTRY_END_CHAR_AS_STRING, 94 | &(message->dict)); 95 | 96 | return message; 97 | } 98 | 99 | void modbus_msg_release(void* vmessage) { 100 | ModbusMessage* message = (ModbusMessage*)vmessage; 101 | // free message 102 | dbus_message_unref(message->msg); 103 | free(message); 104 | } 105 | 106 | const char* modbus_connection_send_msg(void* vconn, void* vmessage) { 107 | DBusConnection* conn = (DBusConnection*)vconn; 108 | ModbusMessage* message = (ModbusMessage*)vmessage; 109 | DBusMessage* reply; 110 | DBusMessageIter rargs; 111 | DBusPendingCall* pending; 112 | char* stat; 113 | 114 | dbus_message_iter_close_container(&(message->args), &(message->dict)); 115 | 116 | // send message and get a handle for a reply 117 | if (!dbus_connection_send_with_reply (conn, message->msg, &pending, -1)) { // -1 is default timeout 118 | fprintf(stderr, "Out Of Memory!\n"); 119 | exit(1); 120 | } 121 | if (NULL == pending) { 122 | fprintf(stderr, "Pending Call Null\n"); 123 | exit(1); 124 | } 125 | dbus_connection_flush(conn); 126 | 127 | // block until we receive a reply 128 | dbus_pending_call_block(pending); 129 | 130 | // get the reply message 131 | reply = dbus_pending_call_steal_reply(pending); 132 | if (NULL == reply) { 133 | fprintf(stderr, "Reply Null\n"); 134 | exit(1); 135 | } 136 | 137 | // free the pending message handle 138 | dbus_pending_call_unref(pending); 139 | 140 | // read the parameters 141 | if (!dbus_message_iter_init(reply, &rargs)) 142 | fprintf(stderr, "Message has no arguments!\n"); 143 | else if (DBUS_TYPE_STRING == dbus_message_iter_get_arg_type(&rargs)) 144 | dbus_message_iter_get_basic(&rargs, &stat); 145 | 146 | 147 | stat = strdup(stat); 148 | // free reply and close connection 149 | dbus_message_unref(reply); 150 | 151 | // printf("Returning: %s\n", stat); 152 | return stat; 153 | } 154 | 155 | void msg_add_entry(const void* vmessage, const char* name, const void* val, 156 | const int type, const char* sig) { 157 | 158 | ModbusMessage* message = (ModbusMessage*)vmessage; 159 | 160 | /* prepare dictionary entry */ 161 | DBusMessageIter entry; 162 | dbus_message_iter_open_container(&(message->dict), DBUS_TYPE_DICT_ENTRY, 0, &entry); 163 | dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &name); 164 | 165 | /* stuff value into variant */ 166 | DBusMessageIter var; 167 | dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, sig, &var); 168 | dbus_message_iter_append_basic(&var, type, val); 169 | dbus_message_iter_close_container(&entry, &var); 170 | 171 | /* close dictionary entry */ 172 | dbus_message_iter_close_container(&(message->dict), &entry); 173 | 174 | } 175 | 176 | void modbus_msg_add_double(void* message, const char* name, double value) { 177 | return msg_add_entry(message, name, &value, DBUS_TYPE_DOUBLE, DBUS_TYPE_DOUBLE_AS_STRING); 178 | } 179 | 180 | void modbus_msg_add_int(void* message, const char* name, int value) { 181 | return msg_add_entry(message, name, &value, DBUS_TYPE_INT32, DBUS_TYPE_INT32_AS_STRING); 182 | } 183 | 184 | void modbus_msg_add_string(void* message, const char* name, const char* value) { 185 | return msg_add_entry(message, name, &value, DBUS_TYPE_STRING, DBUS_TYPE_STRING_AS_STRING); 186 | } 187 | 188 | #ifdef __cplusplus 189 | } 190 | #endif 191 | -------------------------------------------------------------------------------- /lib/modbus/src/c/modbus.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | void* modbus_acquire_session_bus(const char * client_name); 31 | 32 | void modbus_release_bus(void* conn); 33 | 34 | void* modbus_msg_alloc(const char *target, const char* object, const char *interface, const char* method); 35 | 36 | void modbus_msg_release(void* msg); 37 | 38 | void modbus_msg_add_double(void* msg, const char* name, double value); 39 | 40 | void modbus_msg_add_int(void* msg, const char* name, int value); 41 | 42 | void modbus_msg_add_string(void* msg, const char* name, const char* value); 43 | 44 | const char* modbus_connection_send_msg(void* vconn, void* vmessage); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/modbus/src/modelica/modbus/package.mo: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | within ModelicaServices; 23 | 24 | package modbus 25 | 26 | model Foo 27 | Connection c = Connection("myName"); 28 | end Foo; 29 | 30 | class Connection 31 | extends ExternalObject; 32 | 33 | function constructor 34 | annotation(Include = "#include ", Library = {"modbus", "dbus-1"}); 35 | input String clientName; 36 | output Connection conn; 37 | external "C" conn = modbus_acquire_session_bus(clientName); 38 | end constructor; 39 | 40 | function destructor 41 | annotation(Include = "#include ", Library = {"modbus", "dbus-1"}); 42 | input Connection conn; 43 | external "C" modbus_release_bus(conn); 44 | end destructor; 45 | 46 | end Connection; 47 | 48 | class Message 49 | extends ExternalObject; 50 | 51 | function constructor 52 | annotation(Include = "#include ", Library = {"modbus", "dbus-1"}); 53 | input String target; 54 | input String object; 55 | input String interface; 56 | input String method; 57 | 58 | output Message msg; 59 | external "C" msg = modbus_msg_alloc(target, object, interface, method); 60 | end constructor; 61 | 62 | function destructor 63 | annotation(Include = "#include ", Library = {"modbus", "dbus-1"}); 64 | input Message msg; 65 | external "C" modbus_msg_release(msg); 66 | end destructor; 67 | 68 | end Message; 69 | 70 | function sendMessage 71 | input Connection conn; 72 | input Message msg; 73 | output String result; 74 | external "C" result = modbus_connection_send_msg(conn, msg); 75 | end sendMessage; 76 | 77 | function addReal 78 | input Message msg; 79 | input String name; 80 | input Real val; 81 | external "C" modbus_msg_add_double(msg, name, val); 82 | end addReal; 83 | 84 | function addInteger 85 | input Message msg; 86 | input String name; 87 | input Integer val; 88 | external "C" modbus_msg_add_int(msg, name, val); 89 | end addInteger; 90 | 91 | function addString 92 | input Message msg; 93 | input String name; 94 | input String val; 95 | external "C" modbus_msg_add_string(msg, name, val); 96 | end addString; 97 | 98 | end modbus; 99 | -------------------------------------------------------------------------------- /lib/modcount/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(modcount_src "${CMAKE_SOURCE_DIR}/lib/modcount/src/") 3 | 4 | # modcount c-library 5 | add_library(modcount "${modcount_src}/c/modcount.c") 6 | 7 | add_definitions(-fPIC) 8 | 9 | if(USE_OMC) 10 | # Modelica library to install 11 | install(DIRECTORY "${modcount_src}/modelica/modcount" 12 | DESTINATION "${OMC_MOD_LIB_DIR}/${MODELICA_SERVICES_LIBRARY}") 13 | 14 | # Install library header 15 | install(FILES "${modcount_src}/c/modcount.h" DESTINATION ${OMC_INCLUDE_DIR}) 16 | 17 | install(TARGETS modcount 18 | LIBRARY DESTINATION ${OMC_LIBRARY_DIR} 19 | ARCHIVE DESTINATION ${OMC_LIBRARY_DIR} 20 | ) 21 | endif(USE_OMC) 22 | -------------------------------------------------------------------------------- /lib/modcount/src/c/modcount.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | #include "modcount.h" 7 | 8 | /** 9 | * This is both a very simple example of an external Modelica library 10 | * and a very useful tool. If you ever find yourself in need for a mutable 11 | * counter in Modelica, use this pattern. 12 | */ 13 | 14 | typedef struct _Context { 15 | int counter; 16 | } Context; 17 | 18 | void* modcount_acquire_context() { 19 | Context* ctxt = (Context*)malloc(sizeof(Context)); 20 | ctxt -> counter = 0; 21 | return ctxt; 22 | } 23 | 24 | int modcount_get(void* vctxt) { 25 | Context* ctxt = (Context*)vctxt; 26 | return ctxt -> counter; 27 | } 28 | 29 | int modcount_set(void* vctxt, int val) { 30 | Context* ctxt = (Context*)vctxt; 31 | ctxt -> counter = val; 32 | return ctxt -> counter; 33 | } 34 | 35 | void modcount_release_context(void* vctxt) { 36 | free(vctxt); 37 | } 38 | 39 | /** 40 | * Modelica tools will free strings passed to external functions, 41 | * so we need to hide our string objects on the heap... 42 | */ 43 | void* modcount_acquire_string(const char *content) { 44 | /* we do not know modelica's string length 45 | Instead of char*, we could also use C++ std::string here ... 46 | */ 47 | char **res = (char**) malloc(sizeof(char*)); 48 | const size_t len = strlen(content); 49 | char* buf = (char*)calloc(len+1, sizeof(char)); // +1 since it is 0-terminated 50 | strcpy(buf, content); 51 | *res = buf; 52 | return (void*) res; 53 | } 54 | 55 | void modcount_release_string(void *obj) { 56 | char **str = (char**) obj; 57 | free(*str); 58 | free(str); 59 | } 60 | 61 | const char* modcount_get_string(void *str) { 62 | /* copy, so omc does _not_ free */ 63 | const char** content = (const char**) str; 64 | const size_t len = strlen(*content); 65 | char* buf = (char*)calloc(len+1,sizeof(char)); // +1 since it is 0-terminated 66 | strncpy(buf, *content, len+1); 67 | return buf; 68 | } 69 | 70 | void modcount_set_string(void *obj, const char *content) { 71 | const size_t len = strlen(content); 72 | char **res = (char**) obj; 73 | *res = realloc(*res, sizeof(char)*(len+1)); 74 | strncpy(*res, content, len+1); 75 | } 76 | -------------------------------------------------------------------------------- /lib/modcount/src/c/modcount.h: -------------------------------------------------------------------------------- 1 | void* modcount_acquire_context(); 2 | 3 | void modcount_release_context(void* vctxt); 4 | 5 | int modcount_get(void* vctxt); 6 | 7 | int modcount_set(void* vctxt, int val); 8 | 9 | void* modcount_acquire_string(const char* content); 10 | 11 | void modcount_release_string(void* str); 12 | 13 | const char* modcount_get_string(void* str); 14 | -------------------------------------------------------------------------------- /lib/modcount/src/modelica/Test.mo: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | model Test 23 | import ModelicaServices.modcount; 24 | 25 | /* whenever this function is evaluated, increase the counter */ 26 | function f 27 | input modcount.Context context; 28 | input Real x; 29 | output Real y; 30 | 31 | algorithm 32 | modcount.increase_get(context); 33 | y := x; 34 | end f; 35 | 36 | Real x; 37 | Integer i; 38 | modcount.Context context = modcount.Context(); 39 | 40 | equation 41 | when sample(1,1) then 42 | /* read the counter */ 43 | i = modcount.get(context); 44 | end when; 45 | 46 | der(x) = f(context, time); 47 | 48 | end Test; 49 | -------------------------------------------------------------------------------- /lib/modcount/src/modelica/modcount/package.mo: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | within ModelicaServices; 23 | 24 | package modcount 25 | 26 | class Context 27 | extends ExternalObject; 28 | 29 | function constructor 30 | annotation(Include = "#include ", Library = {"modcount"}); 31 | output Context context; 32 | external "C" context = modcount_acquire_context(); 33 | end constructor; 34 | 35 | function destructor 36 | annotation(Include = "#include ", Library = {"modcount"}); 37 | input Context context; 38 | external "C" modcount_release_context(context); 39 | end destructor; 40 | end Context; 41 | 42 | function set 43 | annotation(Include = "#include ", Library = {"modcount"}); 44 | input Context c; 45 | input Integer i; 46 | output Integer out; 47 | external "C" out = modcount_set(c, i); 48 | end set; 49 | 50 | function get 51 | annotation(Include = "#include ", Library = {"modcount"}); 52 | input Context c; 53 | output Integer i; 54 | external "C" i = modcount_get(c); 55 | end get; 56 | 57 | function increase_get 58 | input Context c; 59 | output Integer i; 60 | algorithm 61 | i := get(c); 62 | i := set(c, i + 1); 63 | end increase_get; 64 | 65 | class HeapString 66 | extends ExternalObject; 67 | 68 | function constructor 69 | annotation(Include = "#include ", Library = {"modcount"}); 70 | input String content; 71 | output HeapString str; 72 | external "C" str = modcount_acquire_string(content); 73 | end constructor; 74 | 75 | function destructor 76 | annotation(Include = "#include ", Library = {"modcount"}); 77 | input HeapString str; 78 | external "C" modcount_release_string(str); 79 | end destructor; 80 | end HeapString; 81 | 82 | function setString 83 | input HeapString str; 84 | input String val; 85 | annotation(Include = "#include ", Library = {"modcount"}); 86 | external "C" modcount_set_string(str,val); 87 | end setString; 88 | 89 | function getString 90 | input HeapString str; 91 | output String val; 92 | annotation(Include = "#include ", Library = {"modcount"}); 93 | external "C" val = modcount_get_string(str); 94 | end getString; 95 | 96 | end modcount; 97 | -------------------------------------------------------------------------------- /lib/proc3d/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Boost REQUIRED) 2 | 3 | if(MINGW) 4 | add_definitions(-std=c++0x -fPIC -U__STRICT_ANSI__) 5 | else(MINGW) 6 | add_definitions(-std=c++0x -fPIC) 7 | endif(MINGW) 8 | 9 | include_directories(${Boost_INCLUDE_DIR}) 10 | set(proc3d_src "${CMAKE_SOURCE_DIR}/lib/proc3d/src/") 11 | 12 | add_library(proc3d SHARED "${proc3d_src}/proc3d.cpp") 13 | 14 | install(TARGETS proc3d 15 | RUNTIME DESTINATION bin 16 | LIBRARY DESTINATION lib 17 | ARCHIVE DESTINATION lib 18 | ) 19 | -------------------------------------------------------------------------------- /lib/proc3d/src/animationContext.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "operations.hpp" 26 | 27 | namespace proc3d { 28 | 29 | struct get_time : boost::static_visitor { 30 | template 31 | double operator()(const T& op) const { 32 | return op.time; 33 | } 34 | }; 35 | 36 | static inline double time_of(const AnimOperation& op) { 37 | return boost::apply_visitor( get_time(), op ); 38 | } 39 | 40 | struct compare_frames : boost::static_visitor { 41 | template 42 | bool operator()(const T1& op1, const T2& op2) const { 43 | return op1.time > op2.time; 44 | } 45 | }; 46 | 47 | struct AnimationComparator { 48 | bool operator()(const AnimOperation& op1, const AnimOperation& op2) const { 49 | return boost::apply_visitor( compare_frames(), op1, op2 ); 50 | } 51 | }; 52 | 53 | typedef std::priority_queue, AnimationComparator> animation_queue; 54 | class AnimationContext { 55 | public: 56 | std::queue setupOps; 57 | animation_queue deltaOps; 58 | 59 | virtual void handleSignal(const int signal) { 60 | }; 61 | }; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /lib/proc3d/src/operations.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace proc3d { 29 | 30 | using namespace boost; //array, variant 31 | using namespace boost::numeric::ublas; //bounded_matrix 32 | 33 | struct ObjectOperation { 34 | ObjectOperation(const std::string& name) : name(name) {} 35 | std::string name; 36 | }; 37 | 38 | struct CreateGroup : ObjectOperation { 39 | CreateGroup(const std::string& name) : ObjectOperation(name) {} 40 | }; 41 | 42 | struct LoadObject : ObjectOperation { 43 | LoadObject(const std::string& name, const std::string& f, const array& a) : ObjectOperation(name), fileName(f), at(a) {} 44 | std::string fileName; 45 | array at; 46 | }; 47 | 48 | struct ObjectLinkOperation : ObjectOperation { 49 | ObjectLinkOperation(const std::string& name, const std::string& target) : ObjectOperation(name), target(target) {} 50 | std::string target; 51 | }; 52 | 53 | struct AddToGroup : ObjectLinkOperation { 54 | AddToGroup(const std::string& name, const std::string& target) : ObjectLinkOperation(name, target) {} 55 | }; 56 | 57 | struct CreateMaterial : ObjectOperation { 58 | CreateMaterial(const std::string& name) : ObjectOperation(name) {} 59 | }; 60 | 61 | struct ApplyMaterial : ObjectLinkOperation { 62 | ApplyMaterial(const std::string& name, const std::string& target) : ObjectLinkOperation(name, target) {} 63 | }; 64 | 65 | struct CreateSphere : ObjectOperation { 66 | CreateSphere(const std::string& name, const double r) : ObjectOperation(name), radius(r) {} 67 | double radius; 68 | }; 69 | 70 | struct CreateBox : ObjectOperation { 71 | CreateBox(const std::string& name, const double w, const double l, const double h, const array& a) : ObjectOperation(name), width(w), length(l), height(h), at(a) {} 72 | double width, length, height; 73 | array at; 74 | }; 75 | 76 | struct CreateCylinder : ObjectOperation { 77 | CreateCylinder(const std::string& name, const double r, const double h, const array& a) : ObjectOperation(name), radius(r), height(h), at(a) {} 78 | double radius; 79 | double height; 80 | array at; 81 | }; 82 | 83 | struct CreateCone : ObjectOperation { 84 | CreateCone(const std::string& name, const double r, const double h, const array& a) : ObjectOperation(name), radius(r), height(h), at(a) {} 85 | double radius; 86 | double height; 87 | array at; 88 | }; 89 | 90 | struct CreatePlane : ObjectOperation { 91 | CreatePlane(const std::string& name, const double l, const double w) : ObjectOperation(name), length(l), width(w) {} 92 | double length; 93 | double width; 94 | }; 95 | 96 | struct DeltaOperation : ObjectOperation { 97 | DeltaOperation(const std::string& name, const double t) : ObjectOperation(name), time(t) {} 98 | double time; 99 | }; 100 | 101 | struct Move : DeltaOperation { 102 | Move(const std::string& name, const double t, const double x, const double y, const double z) : DeltaOperation(name, t), x(x), y(y), z(z) {} 103 | double x,y,z; 104 | }; 105 | 106 | struct Scale : DeltaOperation { 107 | Scale(const std::string& name, const double t, const double x, const double y, const double z) : DeltaOperation(name, t), x(x), y(y), z(z) {} 108 | double x,y,z; 109 | }; 110 | 111 | struct RotateEuler : DeltaOperation { 112 | RotateEuler(const std::string& name, const double t, const double x, const double y, const double z) : DeltaOperation(name, t), x(x), y(y), z(z) {} 113 | double x,y,z; 114 | }; 115 | 116 | struct RotateMatrix : DeltaOperation { 117 | RotateMatrix(const std::string& name, const double t, const bounded_matrix& m) : DeltaOperation(name, t), m(m) {} 118 | bounded_matrix m; 119 | }; 120 | 121 | struct SetMaterialProperty : DeltaOperation { 122 | SetMaterialProperty(const std::string& name, const double t, const std::string& p, const double v) : DeltaOperation(name, t), property(p), value(v) {} 123 | std::string property; 124 | double value; 125 | }; 126 | 127 | struct SetAmbientColor : DeltaOperation { 128 | SetAmbientColor(const std::string& name, const double t, 129 | const double r, const double g, const double b, const double a) : 130 | DeltaOperation(name, t) {color[0] = r;color[1] = g;color[2] = b;color[3] = a;} 131 | array color; 132 | }; 133 | 134 | struct SetDiffuseColor : DeltaOperation { 135 | SetDiffuseColor(const std::string& name, const double t, 136 | const double r, const double g, const double b, const double a) : 137 | DeltaOperation(name, t){color[0] = r;color[1] = g;color[2] = b;color[3] = a;} 138 | array color; 139 | }; 140 | 141 | struct SetSpecularColor : DeltaOperation { 142 | SetSpecularColor(const std::string& name, const double t, 143 | const double r, const double g, const double b, const double a) : 144 | DeltaOperation(name, t){color[0] = r;color[1] = g;color[2] = b;color[3] = a;} 145 | array color; 146 | }; 147 | 148 | typedef variant SetupOperation; 151 | 152 | typedef variant AnimOperation; 154 | 155 | } 156 | 157 | 158 | -------------------------------------------------------------------------------- /lib/proc3d/src/proc3d.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #include "proc3d.hpp" 23 | #include "operations.hpp" 24 | #include "animationContext.hpp" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace boost::assign; 31 | 32 | namespace proc3d { 33 | 34 | static inline AnimationContext* getContext(void* ptr) { 35 | return (AnimationContext*) ptr; 36 | } 37 | 38 | extern "C" { 39 | 40 | /* memory management */ 41 | 42 | void* proc3d_animation_context_new() { 43 | return new AnimationContext(); 44 | } 45 | 46 | void proc3d_animation_context_free(void* context) { 47 | delete getContext(context); 48 | } 49 | 50 | /* setup ops */ 51 | 52 | void proc3d_load_object(void* context, const char* name, const char* filename, const double x, const double y, const double z) { 53 | boost::array arr = {x,y,z}; 54 | getContext(context)->setupOps.push(LoadObject(name, filename, arr)); 55 | } 56 | 57 | void proc3d_create_group(void* context, const char* name) { 58 | getContext(context)->setupOps.push(CreateGroup(name)); 59 | } 60 | 61 | void proc3d_create_material(void* context, const char* name, const double r, const double g, const double b, const double a) { 62 | getContext(context)->setupOps.push(CreateMaterial(name)); 63 | } 64 | 65 | void proc3d_create_sphere(void* context, const char* name, const double radius) { 66 | getContext(context)->setupOps.push(CreateSphere(name, radius)); 67 | } 68 | 69 | void proc3d_create_box(void* context, const char* name, 70 | const double x, const double y, const double z, 71 | const double width, const double length, const double height) { 72 | boost::array arr = {x,y,z}; 73 | getContext(context)->setupOps.push(CreateBox(name, width, length, height, arr)); 74 | } 75 | 76 | void proc3d_create_plane(void* context, const char* name, const double width, const double length) { 77 | getContext(context)->setupOps.push(CreatePlane(name, width, length)); 78 | } 79 | 80 | void proc3d_create_cylinder(void* context, const char* name, const double x, const double y, const double z, const double height, const double radius) { 81 | boost::array arr = {x,y,z}; 82 | CreateCylinder cylinder = CreateCylinder(name, radius, height, arr); 83 | getContext(context)->setupOps.push(cylinder); 84 | } 85 | 86 | void proc3d_create_cone(void* context, const char* name, const double x, const double y, const double z, const double height, const double radius) { 87 | boost::array arr = {x,y,z}; 88 | getContext(context)->setupOps.push(CreateCone(name, radius, height, arr)); 89 | } 90 | 91 | void proc3d_add_to_group(void* context, const char* name, const char* target) { 92 | getContext(context)->setupOps.push(AddToGroup(name, target)); 93 | } 94 | 95 | void proc3d_apply_material(void* context, const char* name, const char* target) { 96 | getContext(context)->setupOps.push(ApplyMaterial(name, target)); 97 | } 98 | 99 | /* delta ops */ 100 | 101 | void proc3d_set_rotation_euler(void* context, const char* name, const double x, const double y, const double z, const double time) { 102 | getContext(context)->deltaOps.push(RotateEuler(name, time, x, y, z)); 103 | } 104 | 105 | void proc3d_set_rotation_matrix(void* context, const char* name, 106 | const double r11, const double r12, const double r13, 107 | const double r21, const double r22, const double r23, 108 | const double r31, const double r32, const double r33, 109 | const double time) { 110 | boost::numeric::ublas::bounded_matrix m; 111 | //TODO: This can probably be rewritten with some fancy boost function, I just can't figure out which one ... 112 | m(0,0) = r11; m(0,1) = r12; m(0,2) = r13; 113 | m(1,0) = r21; m(1,1) = r22; m(1,2) = r23; 114 | m(2,0) = r31; m(2,1) = r32; m(2,2) = r33; 115 | 116 | getContext(context)->deltaOps.push(RotateMatrix(name, time, m)); 117 | } 118 | 119 | void proc3d_set_translation(void* context, const char* name, const double x, const double y, const double z, const double time) { 120 | getContext(context)->deltaOps.push(Move(name, time,x,y,z)); 121 | } 122 | 123 | void proc3d_set_scale(void* context, const char* name, const double x, const double y, const double z, const double time) { 124 | getContext(context)->deltaOps.push(Scale(name, time,x,y,z)); 125 | } 126 | 127 | void proc3d_set_material_property(void* context, const char* name, const char* property, const double value, const double time) { 128 | getContext(context)->deltaOps.push(SetMaterialProperty(name, time, property, value)); 129 | } 130 | 131 | void proc3d_set_ambient_color(void* context, const char* name, const double r, const double g, const double b, const double a, const double time) { 132 | getContext(context)->deltaOps.push(SetAmbientColor(name, time, r, g, b, a)); 133 | } 134 | 135 | void proc3d_set_specular_color(void* context, const char* name, const double r, const double g, const double b, const double a, const double time) { 136 | getContext(context)->deltaOps.push(SetSpecularColor(name, time, r, g, b, a)); 137 | } 138 | 139 | void proc3d_set_diffuse_color(void* context, const char* name, const double r, const double g, const double b, const double a, const double time) { 140 | getContext(context)->deltaOps.push(SetDiffuseColor(name, time, r, g, b, a)); 141 | } 142 | 143 | /* signals */ 144 | 145 | void proc3d_send_signal(void* context, const int signal) { 146 | getContext(context)->handleSignal(signal); 147 | } 148 | 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /lib/proc3d/src/proc3d.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Modelica3D package. 3 | 4 | Copyright (C) 2012-current year Christoph Höger and Technical University of Berlin 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with this program. If not, see . 18 | 19 | Main Author 2010-2013, Christoph Höger 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "operations.hpp" 27 | 28 | extern "C" { 29 | 30 | /* memory management */ 31 | 32 | void* proc3d_animation_context_new(); 33 | 34 | void proc3d_animation_context_free(void* pAnimationContext); 35 | 36 | /* setup ops */ 37 | 38 | void proc3d_load_object(void* context, const char* name, const char* filename, const double x, const double y, const double z); 39 | 40 | void proc3d_create_group(void* context, const char* name); 41 | 42 | void proc3d_create_material(void* context, const char* name, const double r, const double g, const double b, const double a); 43 | 44 | void proc3d_create_sphere(void* context, const char* name, const double radius); 45 | 46 | void proc3d_create_box(void* context, const char* name, 47 | const double tx, const double ty, const double tz, 48 | const double width, const double length, const double height); 49 | 50 | void proc3d_create_plane(void* context, const char* name, const double width, const double length); 51 | 52 | void proc3d_create_cylinder(void* context, const char* name, 53 | const double tx, const double ty, const double tz, 54 | const double height, const double radius); 55 | 56 | void proc3d_create_cone(void* context, const char* name, 57 | const double tx, const double ty, const double tz, 58 | const double height, const double radius); 59 | 60 | void proc3d_add_to_group(void* context, const char* name, const char* target); 61 | 62 | void proc3d_apply_material(void* context, const char* name, const char* target); 63 | 64 | /* delta ops */ 65 | 66 | void proc3d_set_rotation_euler(void* context, const char* name, const double x, const double y, const double z, const double time); 67 | 68 | void proc3d_set_rotation_matrix(void* context, const char* name, 69 | const double r11, const double r12, const double r13, 70 | const double r21, const double r22, const double r23, 71 | const double r31, const double r32, const double r33, 72 | const double time); 73 | 74 | void proc3d_set_translation(void* context, const char* name, const double x, const double y, const double z, const double time); 75 | 76 | void proc3d_set_scale(void* context, const char* name, const double x, const double y, const double z, const double time); 77 | 78 | void proc3d_set_material_property(void* context, const char* name, const char* property, const double value, const double time); 79 | 80 | /* coloring */ 81 | void proc3d_set_ambient_color(void* context, const char* name, const double r, const double g, const double b, const double a, const double time); 82 | 83 | void proc3d_set_specular_color(void* context, const char* name, const double r, const double g, const double b, const double a, const double time); 84 | 85 | void proc3d_set_diffuse_color(void* context, const char* name, const double r, const double g, const double b, const double a, const double time); 86 | 87 | /* signals */ 88 | 89 | void proc3d_send_signal(void* context, const int signal); 90 | 91 | } 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_test(NAME "pendulum" 2 | COMMAND ${OMC_COMPILER} "${CMAKE_SOURCE_DIR}/test/test.mos") 3 | -------------------------------------------------------------------------------- /test/test.mos: -------------------------------------------------------------------------------- 1 | loadModelica3D();getErrorString(); 2 | loadString("model DoublePendulum 3 | extends Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum; 4 | inner ModelicaServices.Modelica3D.Controller m3d_control; 5 | end DoublePendulum;");getErrorString(); 6 | system("python " + getInstallationDirectoryPath() + "/lib/omlibrary-modelica3d/osg-gtk/dbus-server.py &");getErrorString(); 7 | res:=simulate(DoublePendulum);getErrorString(); 8 | exit(if res.resultFile <> "" then 0 else 1); 9 | --------------------------------------------------------------------------------