Merge branch 'master' into HEAD

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5428 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
jriegel 2012-01-30 07:06:56 +00:00
commit 38baa94181
13 changed files with 141 additions and 79 deletions

View File

@ -202,7 +202,7 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const
// first check if it's an SVG because Qt's qsvg4 module shouldn't be used therefore
if (icon.isNull()) {
icon = pixmapFromSvg(name, QSize(24,24));
icon = pixmapFromSvg(name, QSize(64,64));
}
// try to find it in the given directories

View File

@ -66,6 +66,9 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent )
QStringList labels; labels << tr("Icons") << tr("Macros");
actionListWidget->setHeaderLabels(labels);
actionListWidget->header()->hide();
actionListWidget->setIconSize(QSize(32, 32));
actionListWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents);
showActions();
}
@ -149,12 +152,9 @@ void DlgCustomActionsImp::showActions()
item->setData(1, Qt::UserRole, actionName);
item->setText(1, QString::fromUtf8((*it)->getMenuText()));
item->setSizeHint(0, QSize(32, 32));
item->setBackgroundColor(0, Qt::lightGray);
if ( (*it)->getPixmap() )
item->setIcon(0, BitmapFactory().pixmap((*it)->getPixmap()));
}
actionListWidget->resizeColumnToContents(0);
}
void DlgCustomActionsImp::on_actionListWidget_itemActivated(QTreeWidgetItem *item)
@ -232,7 +232,6 @@ void DlgCustomActionsImp::on_buttonAddAction_clicked()
item->setData(1, Qt::UserRole, actionName);
item->setText(1, actionMenu->text());
item->setSizeHint(0, QSize(32, 32));
item->setBackgroundColor(0, Qt::lightGray);
if (pixmapLabel->pixmap())
item->setIcon(0, *pixmapLabel->pixmap());

View File

@ -112,6 +112,8 @@ DlgCustomCommandsImp::DlgCustomCommandsImp( QWidget* parent )
labels << tr("Icon") << tr("Command");
commandTreeWidget->setHeaderLabels(labels);
commandTreeWidget->header()->hide();
commandTreeWidget->setIconSize(QSize(32, 32));
commandTreeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents);
categoryTreeWidget->setCurrentItem(categoryTreeWidget->topLevelItem(0));
}
@ -148,13 +150,11 @@ void DlgCustomCommandsImp::onGroupActivated(QTreeWidgetItem* item)
item->setToolTip(1, qApp->translate((*it)->className(), (*it)->getToolTipText()));
item->setData(1, Qt::UserRole, QByteArray((*it)->getName()));
item->setSizeHint(0, QSize(32, 32));
item->setBackgroundColor(0, Qt::lightGray);
if ((*it)->getPixmap())
item->setIcon(0, BitmapFactory().pixmap((*it)->getPixmap()));
}
textLabel->setText(QString());
commandTreeWidget->resizeColumnToContents(0);
}
void DlgCustomCommandsImp::onAddMacroAction(const QByteArray& macro)

View File

@ -101,6 +101,9 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent )
labels << tr("Icon") << tr("Command");
commandTreeWidget->setHeaderLabels(labels);
commandTreeWidget->header()->hide();
commandTreeWidget->setIconSize(QSize(32, 32));
commandTreeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents);
assignedTreeWidget->setHeaderLabels(labels);
assignedTreeWidget->header()->hide();
}
@ -177,12 +180,9 @@ void DlgCustomKeyboardImp::on_categoryBox_activated(int index)
item->setToolTip(1, qApp->translate((*it)->className(), (*it)->getToolTipText()));
item->setData(1, Qt::UserRole, QByteArray((*it)->getName()));
item->setSizeHint(0, QSize(32, 32));
item->setBackgroundColor(0, Qt::lightGray);
if ((*it)->getPixmap())
item->setIcon(0, BitmapFactory().pixmap((*it)->getPixmap()));
}
commandTreeWidget->resizeColumnToContents(0);
}
/** Assigns a new accelerator to the selected command. */

View File

@ -117,6 +117,9 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent)
labels << tr("Icon") << tr("Command");
commandTreeWidget->setHeaderLabels(labels);
commandTreeWidget->header()->hide();
commandTreeWidget->setIconSize(QSize(32, 32));
commandTreeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents);
labels.clear(); labels << tr("Command");
toolbarTreeWidget->setHeaderLabels(labels);
toolbarTreeWidget->header()->hide();
@ -187,19 +190,15 @@ void DlgCustomToolbars::on_categoryBox_activated(int index)
sepitem->setText(1, tr("<Separator>"));
sepitem->setData(1, Qt::UserRole, QByteArray("Separator"));
sepitem->setSizeHint(0, QSize(32, 32));
sepitem->setBackgroundColor(0, Qt::lightGray);
for (std::vector<Command*>::iterator it = aCmds.begin(); it != aCmds.end(); ++it) {
QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
item->setText(1, qApp->translate((*it)->className(), (*it)->getMenuText()));
item->setToolTip(1, qApp->translate((*it)->className(), (*it)->getToolTipText()));
item->setData(1, Qt::UserRole, QByteArray((*it)->getName()));
item->setSizeHint(0, QSize(32, 32));
item->setBackgroundColor(0, Qt::lightGray);
if ((*it)->getPixmap())
item->setIcon(0, BitmapFactory().pixmap((*it)->getPixmap()));
}
commandTreeWidget->resizeColumnToContents(0);
}
void DlgCustomToolbars::on_workbenchBox_activated(int index)

View File

@ -264,20 +264,22 @@ def mergeCells(objectslist):
def download(url):
'''downloads a file from the given URL and saves it in the
user directory. Returns the path to the saved file'''
import urllib2, os
name = url.split('/')[-1]
filepath = os.path.join(FreeCAD.ConfigGet("UserAppData"),name)
if os.path.exists(filepath):
return filepath
try:
FreeCAD.Console.PrintMessage("downloading "+url+" ...\n")
import urllib2, os
response = urllib2.urlopen(url)
s = response.read()
fp = os.path.join(FreeCAD.ConfigGet("UserAppData"),url.split('/')[-1])
if not os.path.exists(fp):
f = open(fp,'wb')
f.write(s)
f.close()
f = open(filepath,'wb')
f.write(s)
f.close()
except:
return None
else:
return fp
return filepath
# command definitions ###############################################

View File

@ -49,6 +49,31 @@ def makeWall(baseobj=None,width=None,height=None,align="Center",name="Wall"):
obj.ViewObject.ShapeColor = (r,g,b,1.0)
return obj
def joinWalls(walls):
"joins the given list of walls into one sketch-based wall"
if not walls:
return None
if not isinstance(walls,list):
walls = [walls]
base = walls.pop()
if base.Base:
if base.Base.Shape.Faces:
return None
if Draft.getType(base.Base) == "Sketch":
sk = base.Base
else:
sk = Draft.makeSketch(base.Base,autoconstraints=True)
old = base.Base.name
base.Base = sk
FreeCAD.ActiveDocument.removeObject(old)
for w in walls:
if w.Base:
if not base.Base.Shape.Faces:
for e in base.Base.Shape.Edges:
sk.addGeometry(e)
FreeCAD.ActiveDocument.recompute()
return base
class _CommandWall:
"the Arch Wall command definition"
def GetResources(self):
@ -60,6 +85,7 @@ class _CommandWall:
def Activated(self):
sel = FreeCADGui.Selection.getSelection()
done = False
self.existing = []
if sel:
import Draft
if Draft.getType(sel[0]) != "Wall":
@ -76,6 +102,13 @@ class _CommandWall:
def getPoint(self,point):
"this function is called by the snapper when it has a 3D point"
pos = FreeCADGui.ActiveDocument.ActiveView.getCursorPos()
exi = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo(pos)
if exi:
exi = FreeCAD.ActiveDocument.getObject(exi['Object'])
if Draft.getType(exi) == "Wall":
if not exi in self.existing:
self.existing.append(exi)
if point == None:
self.tracker.finalize()
return
@ -84,18 +117,22 @@ class _CommandWall:
self.tracker.on()
FreeCADGui.Snapper.getPoint(last=self.points[0],callback=self.getPoint,movecallback=self.update)
elif len(self.points) == 2:
import Draft
l = Draft.makeWire(self.points)
makeWall(l)
import Part
l = Part.Line(self.points[0],self.points[1])
if not self.existing:
s = FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject","WallTrace")
s.addGeometry(l)
makeWall(s)
else:
w = joinWalls(self.existing)
w.Base.addGeometry(l)
self.tracker.finalize()
FreeCAD.ActiveDocument.recompute()
def update(self,point):
"this function is called by the Snapper when the mouse is moved"
self.tracker.update([self.points[0],point])
class _Wall(ArchComponent.Component):
"The Wall object"
def __init__(self,obj):

View File

@ -153,12 +153,9 @@ def getMesh(obj):
def getShape(obj):
"gets a shape from an IfcOpenShell object"
tf = tempfile.mkstemp(suffix=".brp")[1]
of = pyopen(tf,"wb")
of.write(obj.mesh.brep_data)
of.close()
sh = Part.read(tf)
os.remove(tf)
import StringIO
sh=Part.Shape()
sh.importBrep(StringIO.StringIO(obj.mesh.brep_data))
m = obj.matrix
mat = FreeCAD.Matrix(m[0], m[3], m[6], m[9],
m[1], m[4], m[7], m[10],

View File

@ -151,6 +151,8 @@ def getType(obj):
if "Proxy" in obj.PropertiesList:
if hasattr(obj.Proxy,"Type"):
return obj.Proxy.Type
if obj.isDerivedFrom("Sketcher::SketchObject"):
return "Sketch"
if obj.isDerivedFrom("Part::Feature"):
return "Part"
if (obj.Type == "App::Annotation"):
@ -516,38 +518,52 @@ def makeText(stringslist,point=Vector(0,0,0),screen=False):
def makeCopy(obj):
'''makeCopy(object): returns an exact copy of an object'''
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
if getType(obj) == "Rectangle":
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
_Rectangle(newobj)
_ViewProviderRectangle(newobj.ViewObject)
elif getType(obj) == "Wire":
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
_Wire(newobj)
_ViewProviderWire(newobj.ViewObject)
elif getType(obj) == "Circle":
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
_Circle(newobj)
_ViewProviderCircle(newobj.ViewObject)
elif getType(obj) == "Polygon":
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
_Polygon(newobj)
_ViewProviderPolygon(newobj.ViewObject)
elif getType(obj) == "BSpline":
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
_BSpline(newobj)
_ViewProviderBSpline(newobj.ViewObject)
elif getType(obj) == "Block":
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
_Block(newobj)
_ViewProviderDraftPart(newobj.ViewObject)
elif getType(obj) == "Structure":
import Arch
Arch._Structure(newobj)
Arch._ViewProviderStructure(newobj.ViewObject)
import ArchStructure
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
ArchStructure._Structure(newobj)
ArchStructure._ViewProviderStructure(newobj.ViewObject)
elif getType(obj) == "Wall":
import Arch
Arch._Wall(newobj)
Arch._ViewProviderWall(newobj.ViewObject)
import ArchWall
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
ArchWall._Wall(newobj)
ArchWall._ViewProviderWall(newobj.ViewObject)
elif getType(obj) == "Window":
import Arch
Arch._Window(newobj)
Arch._ViewProviderWindow(newobj.ViewObject)
import ArchWindow
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
ArchWindow._Window(newobj)
Archwindow._ViewProviderWindow(newobj.ViewObject)
elif getType(obj) == "Cell":
import ArchCell
newobj = FreeCAD.ActiveDocument.addObject(obj.Type,getRealName(obj.Name))
ArchCell._Cell(newobj)
ArchCell._ViewProviderCell(newobj.ViewObject)
elif obj.isDerivedFrom("Part::Feature"):
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature",getRealName(obj.Name))
newobj.Shape = obj.Shape
else:
print "Error: Object type cannot be copied"

View File

@ -189,7 +189,17 @@ class Snapper:
# active snapping
comp = info['Component']
if obj.isDerivedFrom("Part::Feature"):
if (Draft.getType(obj) == "Wall") and not oldActive:
if obj.Base:
for edge in obj.Base.Shape.Edges:
snaps.extend(self.snapToEndpoints(edge))
snaps.extend(self.snapToMidpoint(edge))
snaps.extend(self.snapToPerpendicular(edge,lastpoint))
snaps.extend(self.snapToIntersection(edge))
snaps.extend(self.snapToElines(edge,eline))
elif obj.isDerivedFrom("Part::Feature"):
if (not self.maxEdges) or (len(obj.Edges) <= self.maxEdges):
if "Edge" in comp:
# we are snapping to an edge
@ -297,16 +307,17 @@ class Snapper:
np = self.getPerpendicular(e,point)
if not fcgeo.isPtOnEdge(np,e):
if (np.sub(point)).Length < self.radius:
if self.tracker:
self.tracker.setCoords(np)
self.tracker.setMarker(self.mk['extension'])
self.tracker.on()
if self.extLine:
self.extLine.p1(e.Vertexes[0].Point)
self.extLine.p2(np)
self.extLine.on()
self.setCursor('extension')
return np,Part.Line(e.Vertexes[0].Point,np).toShape()
if np != e.Vertexes[0].Point:
if self.tracker:
self.tracker.setCoords(np)
self.tracker.setMarker(self.mk['extension'])
self.tracker.on()
if self.extLine:
self.extLine.p1(e.Vertexes[0].Point)
self.extLine.p2(np)
self.extLine.on()
self.setCursor('extension')
return np,Part.Line(e.Vertexes[0].Point,np).toShape()
else:
if last:
de = Part.Line(last,last.add(fcgeo.vec(e))).toShape()
@ -658,16 +669,17 @@ class Snapper:
def click(event_cb):
event = event_cb.getEvent()
if event.getState() == coin.SoMouseButtonEvent.DOWN:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),self.callbackClick)
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(),self.callbackMove)
FreeCADGui.Snapper.off()
self.ui.offUi()
if self.trackLine:
self.trackLine.off()
if callback:
callback(self.pt)
self.pt = None
if event.getButton() == 1:
if event.getState() == coin.SoMouseButtonEvent.DOWN:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),self.callbackClick)
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(),self.callbackMove)
FreeCADGui.Snapper.off()
self.ui.offUi()
if self.trackLine:
self.trackLine.off()
if callback:
callback(self.pt)
self.pt = None
def cancel():
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(),self.callbackClick)

View File

@ -50,9 +50,10 @@ FreeCAD.svgpatterns = importSVG.getContents(Draft_rc.qt_resource_data,'pattern',
altpat = Draft.getParam("patternFile")
if os.path.isdir(altpat):
for f in os.listdir(altpat):
if '.svg' in f:
if f[-4:].upper() == ".SVG":
p = importSVG.getContents(altpat+os.sep+f,'pattern')
if p: FreeCAD.svgpatterns[p[0]]=p[1]
if p:
FreeCAD.svgpatterns.update(p)
# sets the default working plane
plane = WorkingPlane.plane()
@ -485,15 +486,12 @@ class Line(Creator):
def wipe(self):
"removes all previous segments and starts from last point"
if len(self.node) > 1:
print "nullifying"
# self.obj.Shape.nullify() - for some reason this fails
self.obj.ViewObject.Visibility = False
self.node = [self.node[-1]]
print "setting trackers"
self.linetrack.p1(self.node[0])
self.planetrack.set(self.node[0])
msg(translate("draft", "Pick next point:\n"))
print "done"
def numericInput(self,numx,numy,numz):
"this function gets called by the toolbar when valid x, y, and z have been entered there"

View File

@ -232,13 +232,16 @@ class plane:
def getPlacementFromPoints(points):
"returns a placement from a list of 3 or 4 vectors"
pl = plane()
pl.position = points[0]
pl.u = (points[1].sub(points[0]).normalize())
pl.v = (points[2].sub(points[0]).normalize())
if len(points) == 4:
pl.axis = (points[3].sub(points[0]).normalize())
else:
pl.axis = ((pl.u).cross(pl.v)).normalize()
try:
pl.position = points[0]
pl.u = (points[1].sub(points[0]).normalize())
pl.v = (points[2].sub(points[0]).normalize())
if len(points) == 4:
pl.axis = (points[3].sub(points[0]).normalize())
else:
pl.axis = ((pl.u).cross(pl.v)).normalize()
except:
pass
p = pl.getPlacement()
del pl
return p

View File

@ -896,8 +896,7 @@ def getContents(filename,tag,stringmode=False):
contents = filename
else:
f = pythonopen(filename)
contents = ''
for line in f: contents += line
contents = f.read()
f.close()
contents = contents.replace('\n','_linebreak')
searchpat = '<'+tag+'.*?</'+tag+'>'