GMF how to create different shapes for link decorations - eclipse-gmf

I want to create and apply different shapes for source and target decorations of a connection. I know that I have to extend the polyline class but I can't really undersatnd how it works. Could someone help. Are there any examples? I know that only a few people work with gmf and till now nobody has answered my questions related with gmf but please help!!!

You do not have to extend the Polyline class, just call the setTargetDecoration method (or setSourceDecoration) and pass the decoration figure as an argument. You could also pass different decorators based on some condition. For example, an 'arrowhead' decorator figure can be created like this:
PointList pl = new PointList();
pl.addPoint(0, 0);
pl.addPoint(-2, -1);
pl.addPoint(-2, 1);
PolygonDecoration df = new PolygonDecoration();
df.setFill(true);
df.setBackgroundColor(ColorConstants.white);
df.setTemplate(pl);
Be sure to remove the #generated tag from the modified methods.

Related

Godot: Call external method

Lots of googling and I'm still not grasping what is probably a simple solution.
Scene: "Main". Contains a TileMap "Grid" with a script attached to it "Grid.gd".
Scene: "Player". Contains a KinematicBody2D "Player" with a script attached to it "Player.gd"
In Player.gd, I need to call a method in Grid.gd "_Calculate", pass it two variables, and have it return one variable.
var vNewPosition = Grid._Calculate(vPlayer, vInputDirection)
Error: The identifier "Grid" isn't declared in the current scope.
Obiously I need to reference the Grid.gd script somewhere to access it, but none of the many examples I have tried work.
Thanks in advance,
Josh
Given that
The Main scene has an instance of the Player scene
And
In Player.gd, I need to call a method in Grid.gd "_Calculate", pass it two variables, and have it return one variable.
I'll give you a few options.
The bad way
If Player knows the node path to Grid, it could use get_node to get it.
onready var _grid = get_node("../../grid")
Or something like that.
And then use it:
var vNewPosition = _grid._Calculate(vPlayer, vInputDirection)
This approach is, of course, not recommended. It will break if the node path is wrong.
The common way
Assuming Player does not know the node path (which is more likely), you can export a NodePath variable in Player.gd and use it to get the Grid:
exprort var grid_path:NodePath
onready var _grid = get_node(grid_path)
Then you need to set the Grid Path property in the Main scene to Grid.
This approach is better than the prior one, in that it does not depend on the path to Grid. However it still depends on a Grid being there. If Player makes no sense when there is no Grid, this approach is OK.
The good way
If Grid may or may not be there, and we want Player to work regardless, we can tweak the above approach:
exprort var grid_path:NodePath
onready var _grid = get_node_or_null(grid_path)
And remember to check if grid is null before using it:
if grid == null:
return # or whatever
var vNewPosition = grid._Calculate(vPlayer, vInputDirection)
Or like this:
var vNewPosition = grid._Calculate(vPlayer, vInputDirection) if grid != null else null
Which also allows us to specify a default value that vNewPosition will take when there is no grid (the null at the end of the line). And thus you can have the Player work when there is no Grid, and when there is it will use, and regardless of where (because Main tells it where it is).
This solution is not completely decoupled, because Player still knows grid is a thing that has _Calculate. Also we presume there is zero or one, not multiple. I can think of a way to approach that, but decoupling for the sake of decoupling is unnecessary. I'm calling this good enough for your use case. Yet, let me know if you want the over-engineered way.

How to avoid creating objects to check or get content from Maps in Java

I am implementing my own Map in Java, using a custom class I made.
I already implemented the hashCode and equals without any problem.
I just have a question more related into performance and stuff like that.
So I will check many times in my application if a specific value is inside the map, for that, for that I have to create a object and then use the methods containsKey of Map.
My question is...
Is there any other way? without being always creating the object???
I cant have all the objects in my context universe, so that isn't a way...
I know I can just point the object to 'null' after using it, but still, it's not so elegant, creating objects just to check if there is the same object inside =S
Are there any other conventions?
Thank you very much in advance!
EDIT:
Stuff typed = new Stuff(stuff1, stuff2, (char) stuff3);
if(StuffWarehouse.containsKey(typed))
{
//do stuff
}
//after this I won't want to use that object again so...
typed = null;

Scaling images in JavaFX

I am using ImageViewBuilder to create an ImageView and I need to test the properties preserveRatio , fitWidth and fitheight
I was looking at the docs and still cannot figure out how to.
Help will be appreciated. Here is my code (not SSCCE)
ImageView img = ImageViewBuilder
.create()
.image(new Image("http://projavafx.com/images/earthrise.jpg")) // path to image
.build();
If someone could please update the code to show me how to use the fitHeight() and fitWidth() methods then that would be highly appreciated.
IT is not entirely clear what you are trying to do. To use the fitWidth/fitHeight/preserveRatio properties, you can either use the get/set.. methods or,
ImageView img = ImageViewBuilder
.create()
.image(new Image("http://projavafx.com/images/earthrise.jpg")) // path to image
.build();
img.setFitHeight(value); // or getFitHeight() if that is what you need.
img.setFitWidth(value); // or getFitWidth() if that is what you need.
img.preserveRatioProperty(true); // or isPreserveRation() if that is what you need.
or alternatively, access the properties and then call the get/set methods on those:
img.fitHeightProperty().set(value);
img.fitWidthProperty().set(value);
img.preserveRatioProperty().set(true);
This is pretty basic. If you put more information about what exactly the problem is, then you might get a more specific and less basic answer.
chooks

openmesh EdgeHandle class

So I'm using the OpenMesh library for a project and I'm passed in an EdgeHandle e to a method. Is it possible to see what two faces are joined by this edge? I tried looking online but the documentation for openMesh is very sparse and the stuff for EdgeHandle is even sparser.
Yeah, the OpenMesh "documentation" is pretty aggravating. However, from searching for the face_handle mentioned by tintin, I found this page hidden in it which gives a large number of useful functions:
http://openmesh.org/Documentation/OpenMesh-2.4-Documentation/classOpenMesh_1_1Concepts_1_1KernelT.html
Using the stuff found there, the following works for me:
FaceHandle a = mesh.face_handle(mesh.halfedge_handle(e,0));
FaceHandle b = mesh.face_handle(mesh.halfedge_handle(e,1));
(Technically, I enclosed the right hand sides in a function call, so I haven't tried this exactly as written. The right-hand sides should return some form of FaceHandle, at least.)
It's not hard to deal with this,
HalfedgeHandle halfedge_handle(VertexHandle _vh) const {
return vertex(_vh).halfedge_handle_;
}
using this function, you will be able to generate a half edge handle with the edge_handle. and you can
mymesh.face_handle(_hh);
mesh.face_handle(mesh.opposite_halfedge_handle(_hh));
to get the two face_handle you need.

How can I know the class type of an abstract entity in a NSPredicate?

Using core data I'd like to fetch some data. My model uses some abstract entities, see attached picture, where QuantifiedIngredient is an abstract class.
I'd like to fetch Ingredient entities that have at least one RecipeQuantifiedIngredients, but in the middle is QuantifiedIngredient, which is an abstract class.
How can I do that, how can I test the actual type of an abstract class inside a NSPredicate? Any idea or suggestion?
The only clue I found was:
How can you reference child entity name in a predicate for a fetch request of the parent entity?
Would work a custom property in my QuantifiedIngredient to know if it is a RecipeQuantifiedIngredient? For instance isRecipeQuantifiedIngredient?
Thanks a lot for your help.
If recipe is required in RecipeQuantifiedIngredient, you could try to make a fetch, that checks, if there is any ingredient.recipe. I think, that will work.
The custom property, in kind of flag, will work for you too. You'll just need to set and unset it whenever you add or delete all the recipeQuantifiedIngredient.
I don't want to take the time to translate this into CoreData-speak so here is my thought in SQL:
SELECT * FROM quantifiedIngredients WHERE recipe <> NULL
or something like that. This is essentially Nikita's suggestion of using a flag, except that the 'flag' is the existence of a property. I don't know how CoreData will react when faced with GroceryQuantifiedIngredients that don't have the recipe, I think KVO will throw an exception. You might be so bold as to add a category:
#interface GroceryQuantifiedIngredients (KVOHack)
-(id)recipe;
#end
#implementation GroceryQuantifiedIngredients (KVOHack)
-(id) recipe { return nil; }
#end
This would of course require CoreData to enumerate all quantifiedIngredients, but I presume it will have to do so anyway, and a the return nil should optimize into tiny code. The other consideration is whether this will have a bad effect on the rest of your code; you will have to make that call.
Another idea which pops to mind as I finish this up is to do something like this (I'm getting really loose with my pseudo-code now):
SELECT * FROM quantifiedIngredients WHERE [i respondsToSelector:#selector(recipe)];
See what I mean? I forget whether CoreData lets you play with some kind of cursor when working with predicates or fetchedThingamabobbers, if it does than I think this is your best bet. Anyway it's Sunday afternoon so that stuff is left as a exercise for the reader.
+1 for a good question.

Resources