Embedding a view to another (QT) application?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
studioa
Posts: 19
Joined: Mon Apr 27, 2009 1:09 pm

Re: Embedding a view to another (QT) application?

Postby studioa » Thu Jan 07, 2010 8:06 pm

Is this similar to "paper space" in AutoCAD and other applications? If yes, can a magnification/scale can be applied to that view?
Is it possible that the view to be arbitrary defined - like a UCS defined by user?
User avatar
yorik
Site Admin
Posts: 11686
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Embedding a view to another (QT) application?

Postby yorik » Fri Jan 08, 2010 2:45 am

Not really, the autocad paper space is more what the drawing module does (look here: http://sourceforge.net/apps/mediawiki/f ... ing_Module ). What this thread talks about is if you want to create your own Qt program, and embed FreeCAD and its 3D view in it. But it will also be useful inside freecad itself, everytime you want to extract the coin representation of a shape.

I think your other questions all will find an answer in the drawing module...
studioa
Posts: 19
Joined: Mon Apr 27, 2009 1:09 pm

Re: Embedding a view to another (QT) application?

Postby studioa » Fri Jan 08, 2010 1:28 pm

yorikvanhavre wrote:Not really, the autocad paper space is more what the drawing module does (look here: http://sourceforge.net/apps/mediawiki/f ... ing_Module ). What this thread talks about is if you want to create your own Qt program, and embed FreeCAD and its 3D view in it. But it will also be useful inside freecad itself, everytime you want to extract the coin representation of a shape.

I think your other questions all will find an answer in the drawing module...

OK - I see - then would be great if the drawing module can do these: align with a particular UCS (in architectural model you have a particular view that needs to be represented, so being able to align the view with that is a must) and chose a particular scale for that (SI 1:200, 1:100, 1:50, 1:20 etc. and English/Imperial 1/64" = 1' - 0", 1/32" = 1' - 0", 1/16" = 1' - 0", 1/8" = 1' - 0", 1/4" = 1' - 0", etc.)

On the other hand, since .svg is used, can that Qt application be Inkscape? I see a link like this

FreeCAD <-> live filter <-> Inkscape

so working in FreeCAD embedding a view like, can that be translated automatically in an Inkscape drawing that is updated in realtime/live. In Inkscape the drawing can be edited for printing ... well something like that could be entirely "embedded" in FreeCAD since Inkscape is open source as well.
User avatar
yorik
Site Admin
Posts: 11686
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Embedding a view to another (QT) application?

Postby yorik » Fri Jan 08, 2010 2:57 pm

Yes, the drawing module can do that, look at the example on the wiki page.
About the "live update", I thought about doing that with blender one of these days too.
From the freecad side, it's totally possible. You can build a python module that sends info (anything from freecad, being 3D data or SVG data) to another python app. Python has all the tools to do that. So I know in blender it should be easy to code a "receiver" module, but I don't know about inkscape.
tangle-spark
Posts: 4
Joined: Wed May 30, 2012 5:28 am

Re: Embedding a view to another (QT) application?

Postby tangle-spark » Wed Jun 06, 2012 3:45 am

hi again, I found it!

Basically yorik's last comment is my dream app, CAD functions working in a CAD application (FreeCAD) bi-directionally linked to 3D functions working in a 3D app (Blender) then the output reporting to a dedicated drawing program (Inkscape?, maybe not - perhaps something more document handler like).

It would blow anything away out there.

(excuse me while I kiss the sky...!)

I'll see if I can digest this thread a bit more.

cheers

Andy
vdbehr
Posts: 18
Joined: Fri Jul 12, 2013 11:17 am

Re: Embedding a view to another (QT) application?

Postby vdbehr » Thu Aug 08, 2013 2:24 pm

Hi I have a parametric model and a Qt dialog to change the parameters. Now I would like to implement the 3D-View from FreeCAD to it, so that FreeCAD GUI is no longer needed.

I have tried this code to implement the FreeCAD 3D view directly:

https://sourceforge.net/apps/mediawiki/ ... FreeCADGui

Code: Select all

from PyQt4 import QtGui, QtCore

def getMainWindow():
	toplevel = QtGui.qApp.topLevelWidgets()
	for i in toplevel:
		if i.metaObject().className() == "Gui::MainWindow":
			return i
	raise Exception("No main window found")
		
mw=getMainWindow()
		
def get3dview(mw):
	childs=mw.findChildren(QtGui.QMainWindow)
	for i in childs:
		if i.metaObject().className()=="Gui::View3DInventor":
			return i
	return None
		
v=get3dview(mw)
		
class Ui_MainWindow(object):
	def setupUi(self, MainWindow):
		MainWindow.setObjectName("MainWindow")
		MainWindow.resize(508, 436)
		self.centralwidget = QtGui.QWidget(MainWindow)
		self.centralwidget.setObjectName("centralwidget")
		self.gridLayout = QtGui.QGridLayout(self.centralwidget)
		self.gridLayout.setObjectName("gridLayout")
		self.mdiArea = QtGui.QMdiArea(self.centralwidget)
		self.mdiArea.setViewMode(QtGui.QMdiArea.TabbedView)
		self.mdiArea.setTabPosition(QtGui.QTabWidget.South)
		self.mdiArea.setObjectName("mdiArea")
		self.gridLayout.addWidget(self.mdiArea, 0, 0, 1, 1)
		MainWindow.setCentralWidget(self.centralwidget)
		self.menubar = QtGui.QMenuBar(MainWindow)
		self.menubar.setGeometry(QtCore.QRect(0, 0, 508, 27))
		self.menubar.setObjectName("menubar")
		MainWindow.setMenuBar(self.menubar)
		self.statusbar = QtGui.QStatusBar(MainWindow)
		self.statusbar.setObjectName("statusbar")
		MainWindow.setStatusBar(self.statusbar)
			
		self.retranslateUi(MainWindow)
		QtCore.QMetaObject.connectSlotsByName(MainWindow)
			
	def retranslateUi(self, MainWindow):
		MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
			
ui=Ui_MainWindow()
my_mw=QtGui.QMainWindow()
ui.setupUi(my_mw)
ui.mdiArea.addSubWindow(v)
my_mw.show()
FreeCADGui.setupWithoutGUI()
The problem is now that I cant hide the FreeCADGUI. I get the error message:
<type 'exceptions.AttributeError'>: 'module' object has no attribute 'setupWithoutGUI'
I've been searching in the module library of FreeCAD and didn't find the attribute setupWithoutGUI either. I think it was a part of older FreeCAD versions and has been removed.

So is there another way to hide the FreeCADGUI? I need only my Qt-dialog and the 3d View of my model.

OS: Windows 7
Platform: 32-bit
Version: 0.13.1828
Python version: 2.6.2
Qt version: 4.5.2
Coin version: 3.1.0
SoQt version: 1.4.1
OCC version: 6.3.0
pperisin
Posts: 695
Joined: Wed Oct 20, 2010 12:29 pm

Re: Embedding a view to another (QT) application?

Postby pperisin » Sat Aug 17, 2013 10:23 pm

Hi,

I think that there is an empty workbench. you can maybe activate that one.

Regards
Petar
wmayer
Site Admin
Posts: 15471
Joined: Thu Feb 19, 2009 10:32 am

Re: Embedding a view to another (QT) application?

Postby wmayer » Mon Aug 19, 2013 12:37 pm

The problem is now that I cant hide the FreeCADGUI. I get the error message:
This means that you are still using the FreeCAD.exe, right?
I've been searching in the module library of FreeCAD and didn't find the attribute setupWithoutGUI either. I think it was a part of older FreeCAD versions and has been removed.
If you import FreeCADGui as a module from within another application you actually load the FreeCADGui.pyd file. This module has a few more methods compared to the case when using the FreeCAD executable directly.

So, you have two options:
* still use FreeCAD.exe, to hide the window use getMainWindow().hide()
* move to FreeCADGui.pyd (instead of using FreeCAD.exe) then you have the method setupWithoutGUI() available
vdbehr
Posts: 18
Joined: Fri Jul 12, 2013 11:17 am

Re: Embedding a view to another (QT) application?

Postby vdbehr » Tue Aug 20, 2013 9:10 am

Thanks a lot, wmayer.

I managed it to work with getMainWindow().hide().

But in future I think i will use freecad from another application. Thanks for this tip!