Removed drawing capabilities (which are covered by another module)

This commit is contained in:
Jose Luis Cercos-Pita 2014-05-06 19:24:01 +02:00 committed by wmayer
parent a212cab150
commit a8d9bde258
5 changed files with 39 additions and 255 deletions

View File

@ -31,7 +31,6 @@ SOURCE_GROUP("shipcreateship" FILES ${ShipCreateShip_SRCS})
SET(ShipOutlineDraw_SRCS
shipOutlineDraw/__init__.py
shipOutlineDraw/Plot.py
shipOutlineDraw/Preview.py
shipOutlineDraw/TaskPanel.py
shipOutlineDraw/TaskPanel.ui

View File

@ -20,7 +20,6 @@ nobase_data_DATA = \
shipCreateShip/TaskPanel.py \
shipCreateShip/TaskPanel.ui \
shipOutlineDraw/__init__.py \
shipOutlineDraw/Plot.py \
shipOutlineDraw/Preview.py \
shipOutlineDraw/TaskPanel.py \
shipOutlineDraw/TaskPanel.ui \

View File

@ -1,145 +0,0 @@
#***************************************************************************
#* *
#* 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 *
#* *
#***************************************************************************
from PySide import QtGui, QtCore
import FreeCAD
import FreeCADGui
from FreeCAD import Base, Vector
import Part
import Units
from shipUtils import Paths
def Plot(scale, sections, shape):
""" Creates the outline draw.
@param scale Plane scale (format 1:scale)
@param sections Computed sections.
@param shape Ship surfaces
@return plotted object (DocumentObject)
"""
msg = QtGui.QApplication.translate(
"ship_console",
"Performing plot",
None,
QtGui.QApplication.UnicodeUTF8)
FreeCAD.Console.PrintMessage(msg + ' (1:{0})...\n'.format(scale))
scale = 1.0 / scale
# Take positions
bounds = [0.0, 0.0, 0.0]
bbox = shape.BoundBox
bounds[0] = bbox.XLength
bounds[1] = bbox.YLength
bounds[2] = bbox.ZLength
xTot = scale * bounds[1] + 32.0 + scale * bounds[0]
yTot = scale * bounds[2] + 32.0 + scale * bounds[1]
xMid = 210.0
yMid = 185.0
x0 = xMid - 0.5 * xTot
y0 = 297.0 - yMid - 0.5 * yTot # 297 = A3_width
# Get border
edges = getEdges([shape])
border = edges[0]
for i in range(0, len(edges)):
border = border.oldFuse(edges[i])
border = border.oldFuse(edges[i].mirror(Vector(0.0, 0.0, 0.0),
Vector(0.0, 1.0, 0.0)))
# Fuse sections & borders
obj = border.oldFuse(sections)
# Send to 3D view
Part.show(obj)
objs = FreeCAD.ActiveDocument.Objects
obj = objs[len(objs) - 1]
# Create a new plane
FreeCAD.ActiveDocument.addObject('Drawing::FeaturePage',
'OutlineDrawPlot')
FreeCAD.ActiveDocument.OutlineDrawPlot.Template = (
FreeCAD.getResourceDir() + 'Mod/Drawing/Templates/A3_Landscape.svg')
# Side view
FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart',
'OutlineDrawSideView')
FreeCAD.ActiveDocument.OutlineDrawSideView.Source = obj
FreeCAD.ActiveDocument.OutlineDrawSideView.Direction = (1.0, 0.0, 0.0)
FreeCAD.ActiveDocument.OutlineDrawSideView.Rotation = -90.0
FreeCAD.ActiveDocument.OutlineDrawSideView.Scale = scale
FreeCAD.ActiveDocument.OutlineDrawSideView.X = (
420.0 - x0 - 0.5 * scale * bounds[1]) # 420 = A3_height
FreeCAD.ActiveDocument.OutlineDrawSideView.Y = (
y0 + 0.5 * scale * bounds[2])
FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(
FreeCAD.ActiveDocument.OutlineDrawSideView)
# Front view
FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart',
'OutlineDrawFrontView')
FreeCAD.ActiveDocument.OutlineDrawFrontView.Source = obj
FreeCAD.ActiveDocument.OutlineDrawFrontView.Direction = (0.0, 1.0, 0.0)
FreeCAD.ActiveDocument.OutlineDrawFrontView.Rotation = -90.0
FreeCAD.ActiveDocument.OutlineDrawFrontView.Scale = scale
FreeCAD.ActiveDocument.OutlineDrawFrontView.X = (
420.0 - x0 - scale * bounds[1] - 32 - 0.5 * scale * bounds[0])
FreeCAD.ActiveDocument.OutlineDrawFrontView.Y = (
y0 + 0.5 * scale * bounds[2])
FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(
FreeCAD.ActiveDocument.OutlineDrawFrontView)
# Up view
FreeCAD.ActiveDocument.addObject('Drawing::FeatureViewPart',
'OutlineDrawUpView')
FreeCAD.ActiveDocument.OutlineDrawUpView.Source = obj
FreeCAD.ActiveDocument.OutlineDrawUpView.Direction = (0.0, 0.0, 1.0)
FreeCAD.ActiveDocument.OutlineDrawUpView.Scale = scale
FreeCAD.ActiveDocument.OutlineDrawUpView.X = (
420.0 - x0 - scale * bounds[1] - 32 - 0.5 * scale * bounds[0])
FreeCAD.ActiveDocument.OutlineDrawUpView.Y = (
y0 + scale * bounds[2] + 32)
FreeCAD.ActiveDocument.OutlineDrawPlot.addObject(
FreeCAD.ActiveDocument.OutlineDrawUpView)
FreeCAD.ActiveDocument.recompute()
return obj
def getEdges(objs=None):
""" Returns object edges (a list of them)
@param objs Object to get the faces, none if the selected object may be
used.
@return Selected edges. None if errors happened
"""
edges = []
if not objs:
objs = FreeCADGui.Selection.getSelection()
if not objs:
return None
for i in range(0, len(objs)):
obj = objs[i]
if obj.isDerivedFrom('Part::Feature'):
# get shape
shape = obj.Shape
if not shape:
return None
obj = shape
if not obj.isDerivedFrom('Part::TopoShape'):
return None
objEdges = obj.Edges
if not objEdges:
continue
for j in range(0, len(objEdges)):
edges.append(objEdges[j])
return edges

View File

@ -22,10 +22,11 @@
#***************************************************************************
import FreeCAD as App
from FreeCAD import Base, Vector
import FreeCADGui as Gui
import Part
from PySide import QtGui, QtCore
import Preview
import Plot
import Instance
from shipUtils import Paths
@ -42,18 +43,48 @@ class TaskPanel:
self.preview = Preview.Preview()
def accept(self):
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.scale = self.widget(QtGui.QSpinBox, "Scale")
self.saveSections()
self.obj = Plot.Plot(form.scale.value(),
self.obj.Shape,
self.ship.Shape)
# Add ship edges to the object
edges = self.getEdges([self.ship.Shape])
border = edges[0]
for i in range(len(edges)):
border = border.oldFuse(edges[i])
border = border.oldFuse(edges[i].mirror(Vector(0.0, 0.0, 0.0),
Vector(0.0, 1.0, 0.0)))
obj = border.oldFuse(self.obj.Shape)
# Send the generated object to the scene
Part.show(obj)
objs = App.ActiveDocument.Objects
self.obj = objs[len(objs) - 1]
self.preview.clean()
self.obj.Label = 'OutlineDraw'
return True
def getEdges(self, objs):
"""Return object edges (as a list)
"""
edges = []
if not objs:
return None
for i in range(len(objs)):
obj = objs[i]
if obj.isDerivedFrom('Part::Feature'):
# get shape
shape = obj.Shape
if not shape:
return None
obj = shape
if not obj.isDerivedFrom('Part::TopoShape'):
return None
objEdges = obj.Edges
if not objEdges:
continue
for j in range(0, len(objEdges)):
edges.append(objEdges[j])
return edges
def reject(self):
self.preview.clean()
return True
@ -93,7 +124,6 @@ class TaskPanel:
form.deleteButton = self.widget(QtGui.QPushButton, "DeleteButton")
form.nSections = self.widget(QtGui.QSpinBox, "NSections")
form.createButton = self.widget(QtGui.QPushButton, "CreateButton")
form.scale = self.widget(QtGui.QSpinBox, "Scale")
self.form = form
# Initial values
if self.initValues():
@ -203,12 +233,6 @@ class TaskPanel:
"Auto create",
None,
QtGui.QApplication.UnicodeUTF8))
self.widget(QtGui.QGroupBox, "ScaleBox").setTitle(
QtGui.QApplication.translate(
"ship_outline",
"Scale",
None,
QtGui.QApplication.UnicodeUTF8))
self.widget(QtGui.QPushButton, "DeleteButton").setText(
QtGui.QApplication.translate(
"ship_outline",
@ -425,7 +449,6 @@ class TaskPanel:
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.sectionType = self.widget(QtGui.QComboBox, "SectionType")
form.scale = self.widget(QtGui.QSpinBox, "Scale")
# Load sections
props = self.ship.PropertiesList
@ -438,14 +461,6 @@ class TaskPanel:
self.LSections = self.ship.LSections[:]
self.BSections = self.ship.BSections[:]
self.TSections = self.ship.TSections[:]
# Load scale too
flag = True
try:
props.index("PlotScale")
except ValueError:
flag = False
if flag:
form.scale.setValue(self.ship.PlotScale)
# Set UI
self.setSectionType(form.sectionType.currentIndex())
@ -454,7 +469,6 @@ class TaskPanel:
"""
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.scale = self.widget(QtGui.QSpinBox, "Scale")
props = self.ship.PropertiesList
try:
@ -491,20 +505,6 @@ class TaskPanel:
self.ship.LSections = self.LSections[:]
self.ship.BSections = self.BSections[:]
self.ship.TSections = self.TSections[:]
# Save the scale as well
try:
props.index("PlotScale")
except ValueError:
tooltip = str(QtGui.QApplication.translate(
"ship_outline",
"Plot scale (1:scale format)",
None,
QtGui.QApplication.UnicodeUTF8))
self.ship.addProperty("App::PropertyInteger",
"PlotScale",
"Ship",
tooltip).PlotScale = 250
self.ship.PlotScale = form.scale.value()
def createTask():

View File

@ -237,75 +237,6 @@
</item>
</layout>
</item>
<item row="1" column="1" colspan="2">
<widget class="QGroupBox" name="ScaleBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>72</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>96</height>
</size>
</property>
<property name="title">
<string>Plane scale</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="ScaleLabel">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>1:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="Scale">
<property name="minimumSize">
<size>
<width>0</width>
<height>16</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
<property name="value">
<number>250</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>