Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) CustomNode (Read 11206 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
CustomNode
Sep 22nd, 2015 at 4:01pm
Print Post  
Hi,
Is it possible to create a CustomNode with a rectangle inside a circle?
Then how can I set the CustomNode it to a DiagramNode?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #1 - Sep 22nd, 2015 at 4:42pm
Print Post  
Hi,

You could define a custom Shape and apply it to standard ShapeNode:

Code
Select All
float v = (float)Math.cos(Math.PI / 4) * 50;
new Shape(
	// circle part
	Shape.fromId("Ellipse").getOutline(),

	// rect part
    new ElementTemplate[]
    {
        new LineTemplate(50 + v, 50 - v, 50 + v, 50 + v),
        new LineTemplate(50 + v, 50 + v, 50 - v, 50 + v),
        new LineTemplate(50 - v, 50 + v, 50 - v, 50 - v),
        new LineTemplate(50 - v, 50 - v, 50 + v, 50 - v)
    },

    null, Path.FillType.WINDING, "RectInCircle");

diagram.getFactory().createShapeNode(
	10, 10, 50, 50,
	Shape.fromId("RectInCircle")); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #2 - Sep 22nd, 2015 at 4:55pm
Print Post  
Ok, thank you but it doesn't recognize GeneralPath.WIND_NON_ZERO
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #3 - Sep 22nd, 2015 at 4:58pm
Print Post  
Replace that with Path.FillType.WINDING; I've updated code above.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #4 - Sep 22nd, 2015 at 5:07pm
Print Post  
Ok, now it works, but is it possible to set a text inside the rectangle? and to cover only the part of the circle, without coloring inside the rectangle?
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #5 - Sep 23rd, 2015 at 9:29am
Print Post  
Hi,
How can I draw a decision inside a circle?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #6 - Sep 23rd, 2015 at 10:03am
Print Post  
You can show text in nodes by setting ShapeNode.Text property. If you mean the text should only cover some part of the circle, set the third argument (text region; null in code above) to the outline of that part.

Replace the rectangle coordinates above with following to get a decision shape:

Code
Select All
    new ElementTemplate[]
    {
        new LineTemplate(50, 0, 100, 50),
        new LineTemplate(100, 50, 50, 100),
        new LineTemplate(50, 100, 0, 50),
        new LineTemplate(0, 50, 50, 0)
    }, 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #7 - Sep 23rd, 2015 at 10:15am
Print Post  
Ok, thank you very much.
Is it possible to create a CustomNode made up of a circle and a text near the circle? I mean instead of writing the text inside the circle, is it possible to write it outside but near the circle? Here is an example:
  

example1.png ( 2 KB | 150 Downloads )
example1.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #8 - Sep 23rd, 2015 at 12:53pm
Print Post  
You could create a custom shape whose text region's Y coordinates are negative. Alternatively, display the text using a ShapeNode attached to the ellipse, enabling its Transparent property to hide the label node's geometry and leave only text.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #9 - Sep 23rd, 2015 at 1:47pm
Print Post  
Sorry, could you give me an example?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #10 - Sep 23rd, 2015 at 2:33pm
Print Post  
try this shape:

Code
Select All
new Shape(
	// circle part
	Shape.fromId("Ellipse").getOutline(),

	// no decorations
	null,

	// text region
    new ElementTemplate[]
    {
        new LineTemplate(-100, -100, 100, -100),
        new LineTemplate(100, -100, 100, 0),
        new LineTemplate(100, 0, -100, 0),
        new LineTemplate(-100, 0, -100, -100),
    },

    Path.FillType.WINDING, "CircleWithTextAbove"); 

  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #11 - Sep 23rd, 2015 at 3:09pm
Print Post  
ok, thank you very much, it works, but is there a way to make the ellipse of fixed size and display the text anyway, without calling the method resizeToFitText? I mean I want a small ellipse about 1.5, 1.5 and the text displayed anyway outside.
Then I have another problem, I don't want that the text is covered by the ellipse, it should be near the ellipse but the whole text must be displayed well without covered parts
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #12 - Sep 23rd, 2015 at 5:20pm
Print Post  
The Shape definition coordinates are specified as percentage, so if the node will be that small, you will have to set a few timer larger values, e.g. in X:[-400:500] and Y:[-500:0] range. Set text line alignment to bottom and the text should start from default margin distance above the ellipse. In previous case when text region was smaller and using default centered line alignment, it would overlap the shape indeed.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: CustomNode
Reply #13 - Sep 23rd, 2015 at 5:25pm
Print Post  
Sorry, I haven't understood, could you give me an example?
I did this: 
if (s.getShape() == Shape.fromId("CircleWithTextAbove")) {
        s.setShadowOffsetX(0);
        s.setShadowOffsetY(0);
        s.setText(sname);
                                                         s.resizeToFitText(FitSize.KeepRatio);
    s.resize(3, 3);
}
but I want the text not to be overwritten by the ellipse margin and I want the ellipse to be of fixed size 3
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: CustomNode
Reply #14 - Sep 23rd, 2015 at 5:58pm
Print Post  
e.g. try this shape and do not call resizeToFit. If you need to display larger texts on a single row, you might have to set even larger left/right coordinates;

Code
Select All
float l = -300;  // text bounds left, in %
float r = 400;
float t = -500;
float b = 0;
new Shape(
	// circle part
	Shape.fromId("Ellipse").getOutline(),

	// no decorations
	null,

	// text region
    new ElementTemplate[]
    {
        new LineTemplate(l, t, r, t),
        new LineTemplate(r, t, r, b),
        new LineTemplate(r, b, l, b),
        new LineTemplate(l, b, l, t),
    },

    Path.FillType.WINDING, "CircleWithTextAbove");  



Call shapeNode.setTextFormat(new TextFormat(Align.Center, Align.Far)) to bottom-align the text in text region which is above the ellipse, and the text should stay at default 1 millimeter margin distance from its top. You can change that distance by calling setTextPadding method.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint