Regenrated the branch (rebase failed)

This commit is contained in:
J.L. Cercos-Pita
2014-12-12 12:08:35 +01:00
committed by Yorik van Havre
parent 20dbf0c2ae
commit 434012575f
34 changed files with 5115 additions and 247 deletions

View File

@@ -0,0 +1,190 @@
#***************************************************************************
#* *
#* Copyright (c) 2011, 2012 *
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD as App
import FreeCADGui as Gui
import Units
from PySide import QtGui, QtCore
import TankInstance as Instance
from shipUtils import Paths
import shipUtils.Units as USys
class TaskPanel:
def __init__(self):
"""Constructor"""
self.ui = Paths.modulePath() + "/shipCreateTank/TaskPanel.ui"
def accept(self):
"""Create the ship instance"""
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.ship = self.widget(QtGui.QComboBox, "Ship")
# Create the object
ship = self.ships[form.ship.currentIndex()]
obj = App.ActiveDocument.addObject("Part::FeaturePython", "Tank")
tank = Instance.Tank(obj, self.solids, ship)
Instance.ViewProviderTank(obj.ViewObject)
# Set it as a child of the ship
tanks = ship.Tanks[:]
tanks.append(obj.Name)
ship.Tanks = tanks
App.ActiveDocument.recompute()
return True
def reject(self):
"""Cancel the job"""
return True
def clicked(self, index):
pass
def open(self):
pass
def needsFullSpace(self):
return True
def isAllowedAlterSelection(self):
return False
def isAllowedAlterView(self):
return True
def isAllowedAlterDocument(self):
return False
def helpRequested(self):
pass
def setupUi(self):
"""Create and configurate the user interface"""
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.ship = self.widget(QtGui.QComboBox, "Ship")
self.form = form
if self.initValues():
return True
self.retranslateUi()
def getMainWindow(self):
toplevel = QtGui.qApp.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise Exception("No main window found")
def widget(self, class_id, name):
"""Return the selected widget.
Keyword arguments:
class_id -- Class identifier
name -- Name of the widget
"""
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
return form.findChild(class_id, name)
def initValues(self):
"""Setup the initial values"""
# Ensure that there are at least one valid object to generate the
# tank
selObjs = Gui.Selection.getSelection()
self.solids = []
if not selObjs:
msg = QtGui.QApplication.translate(
"ship_tank",
"Tanks objects can only be created on top of its geometry"
" (no objects selected)",
None,
QtGui.QApplication.UnicodeUTF8)
App.Console.PrintError(msg + '\n')
return True
for obj in selObjs:
try:
self.solids.extend(obj.Shape.Solids)
except:
continue
if not len(self.solids):
msg = QtGui.QApplication.translate(
"ship_tank",
"No solids found in the selected objects",
None,
QtGui.QApplication.UnicodeUTF8)
App.Console.PrintError(msg + '\n')
return True
# Ensure as well that exist at least one valid ship to create the
# entity inside it
self.ships = []
for obj in App.ActiveDocument.Objects:
try:
if obj.IsShip:
self.ships.append(obj)
except:
continue
if not len(self.ships):
msg = QtGui.QApplication.translate(
"ship_tank",
"There are not ship objects to create weights into them",
None,
QtGui.QApplication.UnicodeUTF8)
App.Console.PrintError(msg + '\n')
return True
# Fill the ships combo box
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.ship = self.widget(QtGui.QComboBox, "Ship")
icon = QtGui.QIcon(QtGui.QPixmap(":/icons/Ship_Instance.svg"))
form.ship.clear()
for ship in self.ships:
form.ship.addItem(icon, ship.Label)
form.ship.setCurrentIndex(0)
return False
def retranslateUi(self):
"""Set the user interface locale strings."""
self.form.setWindowTitle(QtGui.QApplication.translate(
"ship_tank",
"Create a new tank",
None,
QtGui.QApplication.UnicodeUTF8))
self.widget(QtGui.QLabel, "ShipLabel").setText(
QtGui.QApplication.translate(
"ship_tank",
"Ship",
None,
QtGui.QApplication.UnicodeUTF8))
def createTask():
panel = TaskPanel()
Gui.Control.showDialog(panel)
if panel.setupUi():
Gui.Control.closeDialog(panel)
return None
return panel

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TaskPanel</class>
<widget class="QWidget" name="TaskPanel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>78</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Create new tank</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="ShipLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Ship</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="Ship">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,29 @@
#***************************************************************************
#* *
#* Copyright (c) 2011, 2012 *
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import TaskPanel
def load():
"""Loads the tool in the task panel"""
TaskPanel.createTask()