1313import javafx .scene .paint .Color ;
1414
1515public class Group extends AbstractAddFrom implements ICaDoodleOpperation {
16- @ Expose (serialize = true , deserialize = true )
16+ @ Expose (serialize = true , deserialize = true )
1717 private List <String > names = new ArrayList <String >();
18- @ Expose (serialize = true , deserialize = true )
19- public String groupID =null ;
20- @ Expose (serialize = true , deserialize = true )
21- public boolean hull =false ;
18+ @ Expose (serialize = true , deserialize = true )
19+ public String groupID = null ;
20+ @ Expose (serialize = true , deserialize = true )
21+ public boolean hull = false ;
22+ @ Expose (serialize = true , deserialize = true )
23+ public boolean intersect = false ;
24+
2225 @ Override
2326 public String getType () {
2427 return "Group" ;
@@ -31,51 +34,57 @@ public List<CSG> process(List<CSG> incoming) {
3134 ArrayList <CSG > back = new ArrayList <CSG >();
3235 ArrayList <CSG > replace = new ArrayList <CSG >();
3336 back .addAll (incoming );
34- for (CSG csg : incoming ) {
35- if (csg .isLock ())
37+ for (CSG csg : incoming ) {
38+ if (csg .isLock ())
3639 continue ;
37- for (String name : names ) {
38- if (name .contentEquals (csg .getName ())) {
40+ for (String name : names ) {
41+ if (name .contentEquals (csg .getName ())) {
3942 replace .add (csg );
40- CSG c = csg .clone ().syncProperties (csg ).setRegenerate (csg .getRegenerate ()).setName (name );
41- if (csg .isHole ()) {
43+ CSG c = csg .clone ().syncProperties (csg ).setRegenerate (csg .getRegenerate ()).setName (name );
44+ if (csg .isHole ()) {
4245 holes .add (c );
43- }else
46+ } else
4447 solids .add (c );
4548 c .addGroupMembership (getGroupID ());
4649 back .add (c );
4750 }
4851 }
4952 }
50- for (CSG c : replace ) {
53+ for (CSG c : replace ) {
5154 back .remove (c );
5255 }
53- CSG result =null ;
54- if (holes .size ()> 0 && solids .size ()== 0 ) {
56+ CSG result = null ;
57+ if (holes .size () > 0 && solids .size () == 0 ) {
5558 result = CSG .unionAll (holes );
56- if (hull )
57- result = result .hull ();
59+ if (hull )
60+ result = result .hull ();
5861 result .setIsHole (true );
5962
60- }else {
61- CSG holecutter =null ;
62- if (holes .size ()>0 ) {
63- holecutter =CSG .unionAll (holes );
64- if (hull )
65- holecutter =holecutter .hull ();
63+ } else {
64+ CSG holecutter = null ;
65+ if (holes .size () > 0 ) {
66+ if (intersect )
67+ holecutter = intersect (holes );
68+ else
69+ holecutter = CSG .unionAll (holes );
70+ if (hull )
71+ holecutter = holecutter .hull ();
6672 }
67- result = CSG .unionAll (solids );
73+ if (intersect )
74+ result = intersect (solids );
75+ else
76+ result = CSG .unionAll (solids );
6877 Color c = result .getColor ();
69- if (hull ) {
70- result = result .hull ();
78+ if (hull ) {
79+ result = result .hull ();
7180 }
72- if (holecutter != null )
73- result = result .difference (holecutter );
81+ if (holecutter != null )
82+ result = result .difference (holecutter );
7483 result .setIsHole (false );
7584 result .setColor (c );
7685 }
7786 HashMap <String , IParametric > mapOfparametrics = result .getMapOfparametrics ();
78- if (mapOfparametrics != null )
87+ if (mapOfparametrics != null )
7988 mapOfparametrics .clear ();
8089 result .addIsGroupResult (getGroupID ());
8190 result .setName (getGroupID ());
@@ -84,6 +93,14 @@ public List<CSG> process(List<CSG> incoming) {
8493 return back ;
8594 }
8695
96+ private CSG intersect (ArrayList <CSG > solids ) {
97+ CSG first = solids .get (0 );
98+ for (int i =1 ;i <solids .size ();i ++) {
99+ first =first .intersect (solids .get (i ));
100+ }
101+ return first ;
102+ }
103+
87104 public List <String > getNames () {
88105 return names ;
89106 }
@@ -94,15 +111,21 @@ public Group setNames(List<String> names) {
94111 }
95112
96113 public String getGroupID () {
97- if (groupID == null )
98- groupID = RandomStringFactory .generateRandomString ();
114+ if (groupID == null )
115+ groupID = RandomStringFactory .generateRandomString ();
99116 return groupID ;
100117 }
101118
119+ public Group setIntersect (boolean intersect ) {
120+ this .intersect = intersect ;
121+ return this ;
122+ }
123+
102124 public Group setHull (boolean hull ) {
103125 this .hull = hull ;
104126 return this ;
105127 }
128+
106129 @ Override
107130 public File getFile () throws NoSuchFileException {
108131 throw new NoSuchFileException (null );
0 commit comments