summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java
blob: 754c848a93a82a1e19413591e337b8e573ce6af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
/* ========================================================================
 * PlantUML : a free UML diagram generator
 * ========================================================================
 *
 * (C) Copyright 2009-2020, Arnaud Roques
 *
 * Project Info:  http://plantuml.com
 * 
 * If you like this project or if you find it useful, you can support us at:
 * 
 * http://plantuml.com/patreon (only 1$ per month!)
 * http://plantuml.com/paypal
 * 
 * This file is part of PlantUML.
 *
 * PlantUML is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PlantUML distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 *
 * Original Author:  Arnaud Roques
 * 
 *
 */
package net.sourceforge.plantuml.cucadiagram;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.sourceforge.plantuml.BackSlash;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.creole.CreoleMode;
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramTxtMaker;
import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory;
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.jdot.CucaDiagramFileMakerJDot;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.statediagram.StateDiagram;
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;

public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower {

	static private final boolean G1972 = false;

	// private String namespaceSeparator = ".";
	// private String namespaceSeparator1 = GO1972 ? "::" : ".";
	private String namespaceSeparator = null;
	private boolean namespaceSeparatorHasBeenSet = false;

	public final boolean V1972() {
		if (getPragma().backToLegacyPackage()) {
			return false;
		}
		if (getPragma().useNewPackage()) {
			return true;
		}
		if (G1972)
			return true;
		return false;
	}

	public final boolean mergeIntricated() {
		if (getNamespaceSeparator() == null) {
			return false;
		}
		return this.V1972() && this.getUmlDiagramType() == UmlDiagramType.CLASS;
	}

	public Set<SuperGroup> getAllSuperGroups() {
		return entityFactory.getAllSuperGroups();
	}

	private int horizontalPages = 1;
	private int verticalPages = 1;

	private final List<HideOrShow2> hides2 = new ArrayList<HideOrShow2>();
	private final List<HideOrShow2> removed = new ArrayList<HideOrShow2>();
	protected final EntityFactory entityFactory = new EntityFactory(hides2, removed, this);
	private IGroup currentGroup = entityFactory.getRootGroup();
	private List<Ident> stacks2 = new ArrayList<Ident>();
	private List<IGroup> stacks = new ArrayList<IGroup>();

	private boolean visibilityModifierPresent;

	public abstract IEntity getOrCreateLeaf(Ident ident, Code code, LeafType type, USymbol symbol);

	public Ident cleanIdent(Ident ident) {
		return ident;
	}

	public CucaDiagram(ISkinSimple orig) {
		super(orig);
		this.stacks2.add(Ident.empty());
	}

	private Ident getLastID() {
		if (stacks2.size() == 0) {
			// Thread.dumpStack();
			return Ident.empty();
			// throw new IllegalArgumentException();
		}
		return this.stacks2.get(stacks2.size() - 1);
	}

	final public void setNamespaceSeparator(String namespaceSeparator) {
		this.namespaceSeparatorHasBeenSet = true;
		this.namespaceSeparator = namespaceSeparator;
	}

	final public String getNamespaceSeparator() {
		if (namespaceSeparatorHasBeenSet == false) {
			return V1972() ? "::" : ".";
		}
		return namespaceSeparator;
	}

	@Override
	public boolean hasUrl() {
		for (IEntity entity : getGroups(true)) {
			if (entity.hasUrl()) {
				return true;
			}
		}
		for (IEntity entity : entityFactory.leafs()) {
			if (entity.hasUrl()) {
				return true;
			}
		}
		for (Link link : getLinks()) {
			if (link.hasUrl()) {
				return true;
			}
		}
		return false;
	}

	final public void setLastEntity(ILeaf foo) {
		this.lastEntity = foo;
	}

	final protected ILeaf getOrCreateLeafDefault(Ident idNewLong, Code code, LeafType type, USymbol symbol) {
		checkNotNull(idNewLong);
		if (type == null) {
			throw new IllegalArgumentException();
		}
		ILeaf result;
		if (this.V1972())
			result = entityFactory.getLeafStrict(idNewLong);
		else
			result = entityFactory.getLeaf(code);
		if (result == null) {
			result = createLeafInternal(idNewLong, code, Display.getWithNewlines(code), type, symbol);
			result.setUSymbol(symbol);
		}
		if (result.getLeafType() == LeafType.CLASS && type == LeafType.OBJECT) {
			if (result.muteToType(type, symbol) == false) {
				return null;
			}
		}
		this.lastEntity = result;
		return result;
	}

	public ILeaf createLeaf(Ident idNewLong, Code code, Display display, LeafType type, USymbol symbol) {
		checkNotNull(idNewLong);
		if (entityFactory.getLeafStrict(idNewLong) != null) {
			return null;
			// throw new IllegalArgumentException("Already known: " + code);
		}
		return createLeafInternal(idNewLong, code, display, type, symbol);
	}

	final protected ILeaf createLeafInternal(Ident newIdent, Code code, Display display, LeafType type,
			USymbol symbol) {
		checkNotNull(newIdent);
		if (Display.isNull(display)) {
			display = Display.getWithNewlines(code).withCreoleMode(CreoleMode.SIMPLE_LINE);
		}
		final ILeaf leaf = entityFactory.createLeaf(newIdent, code, display, type, getCurrentGroup(), getHides(),
				getNamespaceSeparator());
		entityFactory.addLeaf(leaf);
		this.lastEntity = leaf;
		leaf.setUSymbol(symbol);
		return leaf;
	}

	final public Ident buildLeafIdent(String id) {
		return getLastID().add(id, getNamespaceSeparator());
	}

	final public Ident buildLeafIdentSpecial(String id) {
		return buildFullyQualified(id);
		// if (namespaceSeparator != null) {
		// if (id.contains(namespaceSeparator)) {
		// return Ident.empty().add(id, namespaceSeparator);
		// }
		// }
		// return getLastID().add(id, namespaceSeparator);
	}

	final public Ident buildFullyQualified(String id) {
		return entityFactory.buildFullyQualified(getLastID(), Ident.empty().add(id, getNamespaceSeparator()));
	}

	final public Code buildCode(String s) {
		if (this.V1972())
			throw new UnsupportedOperationException();
		return CodeImpl.of(s);
	}

	protected final void checkNotNull(Object id) {
		if (id == null) {
			throw new IllegalArgumentException();
		}
	}

	public boolean leafExist(Code code) {
		if (this.V1972())
			throw new UnsupportedOperationException();
		return entityFactory.getLeaf(code) != null;
	}

	public boolean leafExistSmart(Ident ident) {
		return entityFactory.getLeafSmart(ident) != null;
	}

	public boolean leafExistStrict(Ident ident) {
		return entityFactory.getLeafStrict(ident) != null;
	}

	final public Collection<IGroup> getChildrenGroups(IGroup parent) {
		if (this.V1972())
			return getChildrenGroupsIdent1972(parent);
		final Collection<IGroup> result = new ArrayList<IGroup>();
		for (IGroup gg : getGroups(false)) {
			if (gg.getParentContainer() == parent) {
				result.add(gg);
			}
		}
		return Collections.unmodifiableCollection(result);
	}

	private Collection<IGroup> getChildrenGroupsIdent1972(IGroup parent) {
		final Collection<IGroup> result = new ArrayList<IGroup>();
		for (IGroup gg : entityFactory.groups2()) {
			if (gg.getIdent().parent().equals(parent.getIdent())) {
				result.add(gg);
			}
		}
		return Collections.unmodifiableCollection(result);
	}

	final public void gotoGroup(Ident ident, Code code, Display display, GroupType type, IGroup parent,
			NamespaceStrategy strategy) {
		if (this.V1972()) {
			gotoGroupInternalWithNamespace(ident, code, display, code, type, parent);
			return;

		}
		if (strategy == NamespaceStrategy.MULTIPLE) {
			if (getNamespaceSeparator() != null) {
				code = getFullyQualifiedCode1972(code);
			}
			gotoGroupInternalWithNamespace(ident, code, display, code, type, parent);
		} else if (strategy == NamespaceStrategy.SINGLE) {
			final Ident newIdLong = buildLeafIdentSpecial(ident.toString(this.getNamespaceSeparator()));
			gotoGroupExternal(newIdLong, code, display, null, type, parent);
			stacks2.add(newIdLong);
		} else {
			throw new IllegalArgumentException();
		}
	}

	protected final String getNamespace1972(Code fullyCode, String separator) {
		String name = fullyCode.getName();
		if (separator == null) {
			throw new IllegalArgumentException(toString());
		}
		do {
			final int x = name.lastIndexOf(separator);
			if (x == -1) {
				return null;
			}
			name = name.substring(0, x);
		} while (entityFactory.getLeaf(buildCode(name)) != null);
		return name;
	}

	private void gotoGroupInternalWithNamespace(Ident idNewLong, Code code, Display display, Code namespaceNew,
			GroupType type, IGroup parent) {
		this.stacks.add(currentGroup);
		this.stacks2.add(idNewLong);

		if (this.V1972()) {
			gotoGroupInternal(idNewLong, code, display, namespaceNew, type, parent);
			return;
		}
		if (getNamespaceSeparator() == null) {
			gotoGroupInternal(idNewLong, code, display, namespaceNew, type, parent);
			return;
		}

		final String namespaceCurrent = getNamespace1972(code, getNamespaceSeparator());
		if (namespaceCurrent == null) {
			gotoGroupInternal(idNewLong, code, display, namespaceNew, type, parent);
			return;
		}
		final IGroup realParent = entityFactory.getGroup(buildCode(namespaceCurrent));
		if (realParent == null) {
			gotoGroupInternal(idNewLong, code, display, namespaceNew, type, parent);
			return;
		}
		display = Display.create(idNewLong.getLast());
		IGroup result = entityFactory.createGroup(idNewLong, code, display, namespaceNew, type, realParent, getHides(),
				getNamespaceSeparator());

		entityFactory.addGroup(result);
		currentGroup = result;

	}

	public void endGroup() {
		if (stacks2.size() > 0) {
			// Thread.dumpStack();
			stacks2.remove(stacks2.size() - 1);
		}
		if (EntityUtils.groupRoot(currentGroup)) {
			Log.error("No parent group");
			return;
		}
		if (stacks.size() > 0) {
			currentGroup = stacks.remove(stacks.size() - 1);
		} else {
			currentGroup = currentGroup.getParentContainer();
		}
	}

	private void gotoGroupInternal(Ident idNewLong, final Code code, Display display, final Code namespace,
			GroupType type, IGroup parent) {
		if (this.V1972()) {
			gotoGroupInternal1972(idNewLong, code, display, namespace, type, parent);
			return;
		}

		IGroup result = entityFactory.getGroup(code);
		if (result != null) {
			currentGroup = result;
			return;
		}
		if (entityFactory.getLeafStrict(idNewLong) != null) {
			result = entityFactory.muteToGroup(code.getName(), namespace, type, parent);
			result.setDisplay(display);
		} else {
			result = entityFactory.createGroup(idNewLong, code, display, namespace, type, parent, getHides(),
					getNamespaceSeparator());
		}
		entityFactory.addGroup(result);
		currentGroup = result;
	}

	private void gotoGroupInternal1972(Ident idNewLong, final Code code, Display display, final Code namespace,
			GroupType type, IGroup parent) {
		IGroup result = entityFactory.getGroupStrict(idNewLong);
		if (result != null) {
			currentGroup = result;
			return;
		}
		final boolean mutation;
		if (getNamespaceSeparator() == null)
			mutation = entityFactory.getLeafVerySmart(idNewLong) != null;
		else
			mutation = entityFactory.getLeafStrict(idNewLong) != null;
		if (mutation) {
			result = entityFactory.muteToGroup1972(idNewLong, namespace, type, parent);
			result.setDisplay(display);
		} else {
			result = entityFactory.createGroup(idNewLong, code, display, namespace, type, parent, getHides(),
					getNamespaceSeparator());
		}
		entityFactory.addGroup(result);
		currentGroup = result;
		stacks2.set(stacks2.size() - 1, result.getIdent());
	}

	final protected void gotoGroupExternal(Ident newIdLong, final Code code, Display display, final Code namespace,
			GroupType type, IGroup parent) {
		IGroup result = entityFactory.getGroup(code);
		if (result != null) {
			currentGroup = result;
			return;
		}
		if (entityFactory.getLeaf(code) != null) {
			result = entityFactory.muteToGroup(code.getName(), namespace, type, parent);
			result.setDisplay(display);
		} else {
			result = entityFactory.createGroup(newIdLong, code, display, namespace, type, parent, getHides(),
					getNamespaceSeparator());
		}
		entityFactory.addGroup(result);
		// entityFactory.thisIsNotArealGroup(newIdLong);
		currentGroup = result;
	}

	public final void gotoThisGroup(IGroup group) {
		currentGroup = group;
	}

	final protected Code getFullyQualifiedCode1972(Code code) {
		final String separator = getNamespaceSeparator();
		if (separator == null) {
			throw new IllegalArgumentException();
		}
		final String full = code.getName();
		if (full.startsWith(separator)) {
			return buildCode(full.substring(separator.length()));
		}
		if (full.contains(separator)) {
			return buildCode(full);
		}
		if (EntityUtils.groupRoot(currentGroup)) {
			return buildCode(full);
		}
		final Code namespace = currentGroup.getNamespace();
		if (namespace == null) {
			return buildCode(full);
		}
		return buildCode(namespace.getName() + separator + full);
	}

	public final IGroup getCurrentGroup() {
		return currentGroup;
	}

	public final IGroup getGroup(Code code) {
		final IGroup p = entityFactory.getGroup(code);
		if (p == null) {
			throw new IllegalArgumentException();
			// return null;
		}
		return p;
	}

	public final IGroup getGroupStrict(Ident ident) {
		if (!this.V1972())
			throw new UnsupportedOperationException();
		final IGroup p = entityFactory.getGroupStrict(ident);
		if (p == null) {
			throw new IllegalArgumentException();
			// return null;
		}
		return p;
	}

	public final IGroup getGroupVerySmart(Ident ident) {
		if (!this.V1972())
			throw new UnsupportedOperationException();
		final IGroup p = entityFactory.getGroupVerySmart(ident);
		if (p == null) {
			throw new IllegalArgumentException();
			// return null;
		}
		return p;
	}

	public final boolean isGroup(Code code) {
		if (this.V1972())
			return isGroupStrict((Ident) code);
		return leafExist(code) == false && entityFactory.getGroup(code) != null;
	}

	public final boolean isGroupStrict(Ident ident) {
		if (!this.V1972())
			throw new UnsupportedOperationException();
		return leafExistStrict(ident) == false && entityFactory.getGroupStrict(ident) != null;
	}

	public final boolean isGroupVerySmart(Ident ident) {
		if (!this.V1972())
			throw new UnsupportedOperationException();
		return leafExistSmart(ident) == false && entityFactory.getGroupVerySmart(ident) != null;
	}

	public final Collection<IGroup> getGroups(boolean withRootGroup) {
		if (withRootGroup == false) {
			return entityFactory.groups();
		}
		final Collection<IGroup> result = new ArrayList<IGroup>();
		result.add(getRootGroup());
		result.addAll(entityFactory.groups());
		return Collections.unmodifiableCollection(result);
	}

	public IGroup getRootGroup() {
		return entityFactory.getRootGroup();
	}

	public SuperGroup getRootSuperGroup() {
		return entityFactory.getRootSuperGroup();
	}

	public final Collection<ILeaf> getLeafsvalues() {
		return entityFactory.leafs2();
	}

	public final int getLeafssize() {
		return getLeafsvalues().size();
	}

	public final ILeaf getLeaf(Code code) {
		return entityFactory.getLeaf(code);
	}

	public final ILeaf getLeafStrict(Ident ident) {
		return entityFactory.getLeafStrict(ident);
	}

	public final ILeaf getLeafSmart(Ident ident) {
		return entityFactory.getLeafSmart(ident);
	}

	public /* final */ ILeaf getLeafVerySmart(Ident ident) {
		return entityFactory.getLeafVerySmart(ident);
	}

	final public void addLink(Link link) {
		entityFactory.addLink(link);
	}

	final protected void removeLink(Link link) {
		entityFactory.removeLink(link);
	}

	final public List<Link> getLinks() {
		return entityFactory.getLinks();
	}

	final public int getHorizontalPages() {
		return horizontalPages;
	}

	final public void setHorizontalPages(int horizontalPages) {
		this.horizontalPages = horizontalPages;
	}

	final public int getVerticalPages() {
		return verticalPages;
	}

	final public void setVerticalPages(int verticalPages) {
		this.verticalPages = verticalPages;
	}

	@Override
	public int getNbImages() {
		return this.horizontalPages * this.verticalPages;
	}

	abstract protected List<String> getDotStrings();

	final public String[] getDotStringSkek() {
		final List<String> result = new ArrayList<String>();
		for (String s : getDotStrings()) {
			if (s.startsWith("nodesep") || s.startsWith("ranksep")) {
				result.add(s);
			}
		}
		final String aspect = getPragma().getValue("aspect");
		if (aspect != null) {
			result.add("aspect=" + aspect + ";");
		}
		final String ratio = getPragma().getValue("ratio");
		if (ratio != null) {
			result.add("ratio=" + ratio + ";");
		}
		return result.toArray(new String[result.size()]);
	}

	private void createFilesXmi(OutputStream suggestedFile, FileFormat fileFormat) throws IOException {
		final CucaDiagramXmiMaker maker = new CucaDiagramXmiMaker(this, fileFormat);
		maker.createFiles(suggestedFile);
	}

	private void createFilesScxml(OutputStream suggestedFile) throws IOException {
		final StateDiagramScxmlMaker maker = new StateDiagramScxmlMaker((StateDiagram) this);
		maker.createFiles(suggestedFile);
	}

	@Override
	protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
			throws IOException {
		final FileFormat fileFormat = fileFormatOption.getFileFormat();

		if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) {
			try {
				createFilesTxt(os, index, fileFormat);
			} catch (Throwable t) {
				t.printStackTrace(new PrintStream(os));
			}
			return ImageDataSimple.ok();
		}

		if (fileFormat.name().startsWith("XMI")) {
			createFilesXmi(os, fileFormat);
			return ImageDataSimple.ok();
		}

		if (fileFormat == FileFormat.SCXML) {
			createFilesScxml(os);
			return ImageDataSimple.ok();
		}

		if (getUmlDiagramType() == UmlDiagramType.COMPOSITE) {
			throw new UnsupportedOperationException();
		}

		entityFactory.buildSuperGroups();

		final CucaDiagramFileMaker maker = this.isUseJDot()
				? new CucaDiagramFileMakerJDot(this, fileFormatOption.getDefaultStringBounder())
				: new CucaDiagramFileMakerSvek(this);
		final ImageData result = maker.createFile(os, getDotStrings(), fileFormatOption);

		if (result == null) {
			return ImageDataSimple.error();
		}
		this.warningOrError = result.getWarningOrError();
		return result;
	}

	private String warningOrError;

	@Override
	public String getWarningOrError() {
		final String generalWarningOrError = super.getWarningOrError();
		if (warningOrError == null) {
			return generalWarningOrError;
		}
		if (generalWarningOrError == null) {
			return warningOrError;
		}
		return generalWarningOrError + BackSlash.NEWLINE + warningOrError;
	}

	private void createFilesTxt(OutputStream os, int index, FileFormat fileFormat) throws IOException {
		final CucaDiagramTxtMaker maker = new CucaDiagramTxtMaker(this, fileFormat);
		maker.createFiles(os, index);
	}

	public boolean isAutarkic(IGroup g) {
		if (g.getGroupType() == GroupType.PACKAGE) {
			return false;
		}
		if (g.getGroupType() == GroupType.INNER_ACTIVITY) {
			return true;
		}
		if (g.getGroupType() == GroupType.CONCURRENT_ACTIVITY) {
			return true;
		}
		if (g.getGroupType() == GroupType.CONCURRENT_STATE) {
			return true;
		}
		if (getChildrenGroups(g).size() > 0) {
			return false;
		}
		for (Link link : getLinks()) {
			if (EntityUtils.isPureInnerLink3(g, link) == false) {
				return false;
			}
		}
		for (ILeaf leaf : g.getLeafsDirect()) {
			if (leaf.getEntityPosition() != EntityPosition.NORMAL) {
				return false;
			}
		}
		return true;
	}

	private static boolean isNumber(String s) {
		return s.matches("[+-]?(\\.?\\d+|\\d+\\.\\d*)");
	}

	public void resetPragmaLabel() {
		getPragma().undefine("labeldistance");
		getPragma().undefine("labelangle");
	}

	public String getLabeldistance() {
		if (getPragma().isDefine("labeldistance")) {
			final String s = getPragma().getValue("labeldistance");
			if (isNumber(s)) {
				return s;
			}
		}
		if (getPragma().isDefine("defaultlabeldistance")) {
			final String s = getPragma().getValue("defaultlabeldistance");
			if (isNumber(s)) {
				return s;
			}
		}
		// Default in dot 1.0
		return "1.7";
	}

	public String getLabelangle() {
		if (getPragma().isDefine("labelangle")) {
			final String s = getPragma().getValue("labelangle");
			if (isNumber(s)) {
				return s;
			}
		}
		if (getPragma().isDefine("defaultlabelangle")) {
			final String s = getPragma().getValue("defaultlabelangle");
			if (isNumber(s)) {
				return s;
			}
		}
		// Default in dot -25
		return "25";
	}

	final public boolean isEmpty(IGroup gToTest) {
		for (IEntity gg : getGroups(false)) {
			if (gg == gToTest) {
				continue;
			}
			if (gg.getParentContainer() == gToTest) {
				return false;
			}
		}
		return gToTest.size() == 0;
	}

	public final boolean isVisibilityModifierPresent() {
		return visibilityModifierPresent;
	}

	public final void setVisibilityModifierPresent(boolean visibilityModifierPresent) {
		this.visibilityModifierPresent = visibilityModifierPresent;
	}

	public final boolean showPortion(EntityPortion portion, IEntity entity) {
		if (getSkinParam().strictUmlStyle() && portion == EntityPortion.CIRCLED_CHARACTER) {
			return false;
		}
		boolean result = true;
		for (HideOrShow cmd : hideOrShows) {
			if (cmd.portion == portion && cmd.gender.contains(entity)) {
				result = cmd.show;
			}
		}
		return result;
	}

	public final void hideOrShow(EntityGender gender, EntityPortion portions, boolean show) {
		for (EntityPortion portion : portions.asSet()) {
			this.hideOrShows.add(new HideOrShow(gender, portion, show));
		}
	}

	public void hideOrShow(Set<VisibilityModifier> visibilities, boolean show) {
		if (show) {
			hides.removeAll(visibilities);
		} else {
			hides.addAll(visibilities);
		}
	}

	public void hideOrShow2(String what, boolean show) {
		this.hides2.add(new HideOrShow2(what, show));
	}

	public void removeOrRestore(String what, boolean show) {
		this.removed.add(new HideOrShow2(what, show));
	}

	private final List<HideOrShow> hideOrShows = new ArrayList<HideOrShow>();
	private final Set<VisibilityModifier> hides = new HashSet<VisibilityModifier>();

	static class HideOrShow {
		private final EntityGender gender;
		private final EntityPortion portion;
		private final boolean show;

		public HideOrShow(EntityGender gender, EntityPortion portion, boolean show) {
			this.gender = gender;
			this.portion = portion;
			this.show = show;
		}
	}

	public final Set<VisibilityModifier> getHides() {
		return Collections.unmodifiableSet(hides);
	}

	public ColorMapper getColorMapper() {
		return getSkinParam().getColorMapper();
	}

	final public boolean isStandalone(IEntity ent) {
		for (final Link link : getLinks()) {
			if (link.getEntity1() == ent || link.getEntity2() == ent) {
				return false;
			}
		}
		return true;
	}

	final public Link getLastLink() {
		final List<Link> links = getLinks();
		for (int i = links.size() - 1; i >= 0; i--) {
			final Link link = links.get(i);
			if (link.getEntity1().getLeafType() != LeafType.NOTE && link.getEntity2().getLeafType() != LeafType.NOTE) {
				return link;
			}
		}
		return null;
	}

	final public List<Link> getTwoLastLinks() {
		final List<Link> result = new ArrayList<Link>();
		final List<Link> links = getLinks();
		for (int i = links.size() - 1; i >= 0; i--) {
			final Link link = links.get(i);
			if (link.getEntity1().getLeafType() != LeafType.NOTE && link.getEntity2().getLeafType() != LeafType.NOTE) {
				result.add(link);
				if (result.size() == 2) {
					return Collections.unmodifiableList(result);
				}
			}
		}
		return null;
	}

	private ILeaf lastEntity = null;

	final public ILeaf getLastEntity() {
		return lastEntity;
	}

	final public EntityFactory getEntityFactory() {
		return entityFactory;
	}

	public void applySingleStrategy() {
		final MagmaList magmaList = new MagmaList();

		for (IGroup g : getGroups(true)) {
			final List<ILeaf> standalones = new ArrayList<ILeaf>();

			for (ILeaf ent : g.getLeafsDirect()) {
				if (isStandalone(ent)) {
					standalones.add(ent);
				}
			}
			if (standalones.size() < 3) {
				continue;
			}
			final Magma magma = new Magma(this, standalones);
			magma.putInSquare();
			magmaList.add(magma);
		}

		for (IGroup g : getGroups(true)) {
			final MagmaList magmas = magmaList.getMagmas(g);
			if (magmas.size() < 3) {
				continue;
			}
			magmas.putInSquare();
		}

	}

	public boolean isHideEmptyDescriptionForState() {
		return false;
	}

	protected void incRawLayout() {
		entityFactory.incRawLayout();
	}

	public CommandExecutionResult constraintOnLinks(Link link1, Link link2, Display display) {
		final LinkConstraint linkConstraint = new LinkConstraint(link1, link2, display);
		link1.setLinkConstraint(linkConstraint);
		link2.setLinkConstraint(linkConstraint);
		return CommandExecutionResult.ok();
	}

}