Updating an open Scene from another Scene - javafx

I'm trying to send value from Scene A to Scene B. any Idea how to get it done? Also, without opening scene B if it already opened. Thanks

It depends on what type of value it is and if the Scene's are in different classes. But if you were sending the value of a Text object in one scene to another Text object in another scene for instance, then using something like this may help:
Text sceneAvalue = new Text("Scene A value");
Text sceneBvalue = new Text(sceneAvalue.getText());
//add sceneBValue to Scene B however you usually add components to a scene

Related

JavaFX 3D - Scene Camera Issues, SubScene Errors, and MeshViews not Visible

I will try to be as brief as possible while providing enough info so that someone might be able to help point me in the right direction. I am trying to add a 3D scene to the center or a borderpane that will contain a set of meshviews that I read from an obj file using an obj loader that has been well tested by others (so I'm confident it works). I will give my summary step by step and provide an image to show my progress and issues.
I start with my borderpane empty:
Next, I started by taking an example from a book that add me create three primitives and add them to a scene and changed it so that this is added to the center part of my borderpane. I created a method that is tied to the File/Open action that when I click File/Open, it calls that method and creates the primitives and adds them to the center of the borderpane:
Next, I tried to add a camera to the main scene that is created as part of the initial Application start method using the following lines:
(line 29 to 33 were commented out in earlier pictures)
However, this leads to the following issue where the borderpane is projected into the third dimension:
I then tried using a SubScene in the center of the borderpane but kept getting a lot of errors of the type nullpointerexception and the info was too vague for me to use to figure out what it was not happy about.
The other and more important issue that I am dealing with while trying to figure this out, is the final version meant to read a group of meshviews from an obj file and add them to the center does not work. The code reads the obj file and imports the meshviews from it. I have printed out to the console number of meshviews read and it matches what was in the test file, so I feel confident I'm using it correctly and this loader has been used a lot by others so has been tested. But when I try to change out and use that to add meshviews to the center I just get a blank center screen and a console printout showing it read the file and that it read the correct number of meshviews. I have not been able to find a good way to debug/figure this out. so could use some advice on that as well.
Thanks for any help you can provide.
instead of
Scene scene = new Scene(borderPane,sceneWidth,sceneHeight);
add this
Scene scene = new Scene(borderPane,sceneWidth,sceneHeight,true, SceneAntialiasing.BALANCED);
the last two parameters are = depthBuffer and antialiasing

Clone a Scene in JavaFX

Is there a way to clone a scene in JavaFX ?
I currently want to keep a reference of the previous scene but can't find a simple way of doing it (except passing in the previous scene as a parameter to every new class responsible for scene creation).
Heres what I was thinking of doing (this is a snipped of my view controller)
public void switchScene(Scene newScene){
previousScene = currentScene; // something which achieves this without aliasing
currentScene = newScene;
window.setScene(newScene);
}.
However as one can observe this leads to aliasing problems.
Any way to solve this problem ?

Element lookup by ID has no result

With the Scene Builder 2 I created a scene with following structure:
BorderPane -> SplitPane -> AnchroPane -> SplitPane -> AnchorBane. (http://pastebin.com/7LTNh1Jv)
The AnchorPane in the second SplitPane has the ID workbench-anchor. Now I try to get a reference of this AnchorPane via:
final BorderPane rootPane = loader.load();
final Node node = rootPane.lookup("#workbench-anchor");
But node is always NULL.
Does anyone know what I am doing wrong?
Thanks a lot in advance!
Lookups won't work until CSS has been applied, which typically happens on the first frame rendering. You can try performing the lookup after showing the stage. You may also be able to force this by calling
rootPane.applyCSS();
before doing the lookup.
In general, lookups are not a very robust way of finding elements of the scene graph (imho). It's probably better to do any initialization work you need in a controller class, using #FXML injections to reference the nodes.

how to use QT graphic view for drawing

im trying to use the graphic veiw of QT to draw lines
it's possible to draw a multiple objects in the scene but is it possible to do a (real time lines ) drawing inside the Qt scene , and how ?
a sample code would be highly appreciated
thanks in advance
I'm creating a kind of "Framework" to do this. There are 2 approaches:
Handle mouse messages, create a QGraphicsLineItem object, add to Scene and modify it during the creation process.
Derive QGraphicsScene, create a QGraphicsLineItem but NOT added to scene, draw it when drawForeground, added it to scene after finished the creation.
Because QGraphicsScene will index objects in a BSP tree by default, and it will impact the performance when changing items frequently, you can get higher performance when using the 2nd approach during creation, but more code work.
1) Create GraphicsView and Scene
m_graphScen = new QGraphicsScene;
m_graphScen->setSceneRect(0,0,790,290);
m_graphView = new QGraphicsView;
m_graphView->setFixedSize(800, 300);
m_graphView->setScene(m_graphScen);
2) Create a slot which is doing the following by handling the mouse events:
m_graphScen->addLine(0, 250, 700, 250, QPen(QBrush(Qt::black),1));
m_graphView->show();
Also if you need to write or draw text see here.

Sharing same model in two QGraphicScene instances in Qt

I have an application that displays an editor for a diagram using QGraphicsScene object. I would like to create a read only version of the same dialog but have ability for user to see both at the same time.
SimScene* pScene1 = new SimScene(model); // adds model to scene
SimScene* pScene2 = new SimScene(model); // adds model to scene
QGraphicsView* pView1 = new QGraphicsView();
pView1->setScene(pScene2);
QGraphicsView* pView1 = new QGraphicsView();
pView2->setScene(pScene2);
When I create 2 instances of QGraphicsScene and use addItem on the second one it removes all the items from the first one. Does Qt support any sort of sharing of model between scenes? Is my only choice to have same scene and try to customize the view? Later one doesn't seem to work because object selection information is within the graphics items being shared so if I disable flags on them they become read only in both views. Any advice is appreciated. Thanks.
If you just want an interactive and a read-only view on your model you can use a single QGraphicsScene and 2 QGraphicsViews. You just have to call QGraphicsView::setInteractive(false) on one of them. That way you don't have to change any item flags.
I think that you're storing QSceneItems in model classes. Because of that pScene1 and pScene2 are trying to share not only the model itself, but also the scene items. This won't work because any scene item can be placed only on one scene at any given moment.
How to fix it? Make model not aware of any GUI. Let it issue changed() notifications whenever something interesting happens.
Then let each SimScene wrap model into whatever QSceneItems it wants, and process changed() notifications.
Example:
Model:
Graph,
Edge,
Vertex
GUI
SimScene,
QEdge,
QVertex,
QSimInfo,
Qbackground, and so on ...
Also, you add pScene2 twice:
...
pView1->setScene(pScene2);
...
pView2->setScene(pScene2);
And allocate memory for the same pointer twice:
QGraphicsView* pView1 = new QGraphicsView();
...
QGraphicsView* pView1 = new QGraphicsView();

Resources