plugin.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 import os
00019 from roslib.packages import get_pkg_dir
00020 
00021 from python_qt_binding.QtGui import *
00022 from python_qt_binding.QtCore import *
00023 
00024 from airbus_pyqt_extend.QtAgiCore import get_pkg_dir_from_prefix
00025 from airbus_cobot_gui import Plugin, ControlMode
00026 
00027 ## Finally import the RViz bindings themselves.
00028 import rviz
00029 
00030 
00031 ## The MyViz class is the main container widget.
00032 class PluginRviz(Plugin):
00033 
00034     ## MyViz Constructor
00035     ## ^^^^^^^^^^^^^^^^^
00036     ##
00037     ## Its constructor creates and configures all the component widgets:
00038     ## frame, thickness_slider, top_button, and side_button, and adds them
00039     ## to layouts.
00040     def __init__(self, context):
00041         Plugin.__init__(self, context)
00042         
00043         self.frame = None
00044         
00045     def onCreate(self, param):
00046         
00047         yaml = param.getParam("yaml")
00048         yaml = get_pkg_dir_from_prefix(yaml)
00049         
00050         ## rviz.VisualizationFrame is the main container widget of the
00051         ## regular RViz application, with menus, a toolbar, a status
00052         ## bar, and many docked subpanels. In this example, we
00053         ## disable everything so that the only thing visible is the 3D
00054         ## render window.
00055         self.frame = rviz.VisualizationFrame()
00056         
00057         ## The "splash path" is the full path of an image file which
00058         ## gets shown during loading. Setting it to the empty string
00059         ## suppresses that behavior.
00060         self.frame.setSplashPath("")
00061         
00062         ## VisualizationFrame.initialize() must be called before
00063         ## VisualizationFrame.load(). In fact it must be called
00064         ## before most interactions with RViz classes because it
00065         ## instantiates and initializes the VisualizationManager,
00066         ## which is the central class of RViz.
00067         self.frame.initialize()
00068         
00069         ## The reader reads config file data into the config object.
00070         ## VisualizationFrame reads its data from the config object.
00071         reader = rviz.YamlConfigReader()
00072         config = rviz.Config()
00073         
00074         reader.readFile( config, yaml)
00075         self.frame.load( config )
00076         
00077         ## You can also store any other application data you like in
00078         ## the config object. Here we read the window title from the
00079         ## map key called "Title", which has been added by hand to the
00080         ## config file.
00081         self.setWindowTitle( config.mapGetChild( "Title" ).getValue() )
00082         
00083         ## Here we disable the menu bar (from the top), status bar
00084         ## (from the bottom), and the "hide-docks" buttons, which are
00085         ## the tall skinny buttons on the left and right sides of the
00086         ## main render window.
00087         self.frame.setMenuBar( None )
00088         self.frame.setHideButtonVisibility( False )
00089         
00090         ## frame.getManager() returns the VisualizationManager
00091         ## instance, which is a very central class. It has pointers
00092         ## to other manager objects and is generally required to make
00093         ## any changes in an rviz instance.
00094         self.manager = self.frame.getManager()
00095         
00096         ## Since the config file is part of the source code for this
00097         ## example, we know that the first display in the list is the
00098         ## grid we want to control. Here we just save a reference to
00099         ## it for later.
00100         self.grid_display = self.manager.getRootDisplayGroup().getDisplayAt(0)
00101         
00102         ## Here we create the layout and other widgets in the usual Qt way.
00103         layout = QVBoxLayout()
00104         layout.addWidget( self.frame )
00105         
00106         #######
00107         
00108         self.setLayout( layout )
00109     
00110     def onPause(self):
00111         pass
00112     
00113     def onResume(self):
00114         pass
00115     
00116     def onControlModeChanged(self, mode):
00117         
00118         if mode == ControlMode.AUTOMATIC:
00119             self.setEnabled(False)
00120         else:
00121             self.setEnabled(True)
00122     
00123     def onUserChanged(self, user_info):
00124         pass
00125     
00126     def onTranslate(self, lng):
00127         pass
00128     
00129     def onEmergencyStop(self, state):
00130         pass
00131     
00132     def onDestroy(self):
00133         pass
00134 


airbus_plugin_rviz
Author(s): Matignon Martin
autogenerated on Thu Jun 6 2019 17:59:27