00001 /* 00002 PROJETO USPDesigner 00003 MODULO: HIE (Estrutura Hierarquica) 00004 Copyright (C) 1989 a 2008, Marcos Tsuzuki, All rights reserved 00005 Universidade de Sao Paulo, EPUSP-PMR 00006 00007 NOME DO ARQUIVO: hiegrpmn.cpp 00008 Coded by Marcos Tsuzuki 00009 00010 Redistribution and use in source and binary forms, with or without 00011 modification, are permitted provided that the following conditions 00012 are met: 00013 00014 1. Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 00021 3. The names of its contributors may not be used to endorse or promote 00022 products derived from this software without specific prior written 00023 permission. 00024 00025 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00026 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00027 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00028 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00029 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 00037 00038 Any feedback is very welcome. 00039 email: mtsuzuki at usp.br (remove space) 00040 */ 00041 #include <stdio.h> 00042 #include <string.h> 00043 #include "memvirtu.h" 00044 #include "lowparam.h" 00045 #include "lowmacro.h" 00046 #include "lowsolid.h" 00047 #include "vectorop.h" 00048 #include "mancommd.h" 00049 #include "genfunc_.h" 00050 #include "hiegroup.h" 00051 00052 Id MSD_getGroupIdFromName(char *name) 00053 { 00054 GPTYPE g; 00055 int i = 0; 00056 00057 for (AllGroup(g)) 00058 { 00059 if (!strcmp(name, GrpName(g))) 00060 { 00061 return(GrpGroupNo(g)); 00062 } 00063 i++; 00064 if (i == 100) 00065 { 00066 break; 00067 } 00068 } 00069 return((Id) - 1); 00070 } 00071 00072 Id MSD_getMaxGroupId(void) 00073 { 00074 GPTYPE gptr; 00075 Id gn; 00076 00077 if (grpary == GNIL) 00078 { 00079 return(1); 00080 } 00081 gn = GrpGroupNo(grpary); 00082 for (AllGroup(gptr)) 00083 { 00084 if (GrpGroupNo(gptr) > gn) 00085 { 00086 gn = GrpGroupNo(gptr); 00087 } 00088 } 00089 return(gn + 1); 00090 } 00091 00092 int MSD_getNumberOfGroups(void) 00093 { 00094 GPTYPE gptr; 00095 int i = 0; 00096 00097 for (AllGroup(gptr)) 00098 { 00099 i++; 00100 } 00101 return(i); 00102 } 00103 00104 char **MSD_putGroupNameInList(char **list) 00105 { 00106 GPTYPE gptr; 00107 int i = 0; 00108 00109 for (AllGroup(gptr)) 00110 { 00111 list[i] = GrpName(gptr); 00112 i++; 00113 } 00114 return(list); 00115 } 00116 00117 GPTYPE MSD_lowFindGroupByName(char *nam) 00118 { 00119 GPTYPE gptr; 00120 00121 for (AllGroup(gptr)) 00122 { 00123 if (!strcmp(nam, GrpName(gptr))) 00124 { 00125 return(gptr); 00126 } 00127 } 00128 return(GNIL); 00129 } 00130 00131 GPTYPE MSD_getGroup(Id gn) 00132 { 00133 GPTYPE gptr; 00134 00135 for (AllGroup(gptr)) 00136 { 00137 if (GrpGroupNo(gptr) == gn) 00138 { 00139 return(gptr); 00140 } 00141 } 00142 return(GNIL); 00143 } 00144 00145 char MSD_lowIsEmptyGroup(GPTYPE grpptr) 00146 { 00147 GPTYPE gptr; 00148 GPTYPE gfptr; 00149 SPTYPE optr; 00150 00151 for (AllSolids(optr)) 00152 { 00153 if (SolGroup(optr) == grpptr) 00154 { 00155 return(FALSE); 00156 } 00157 } 00158 for (AllGroup(gptr)) 00159 { 00160 if ((gfptr = gptr) != grpptr) 00161 { 00162 while ((gfptr = GrpParent(gfptr)) != GNIL) 00163 { 00164 if (gfptr == grpptr) 00165 { 00166 return(FALSE); 00167 } 00168 } 00169 } 00170 } 00171 return(TRUE); 00172 } 00173 00174 char MSD_lowIsAncestorGroup(GPTYPE ancgptr, GPTYPE desgptr) 00175 { 00176 GPTYPE gptr; 00177 00178 for (gptr = desgptr; gptr != GNIL; gptr = GrpParent(gptr)) 00179 { 00180 if (ancgptr == gptr) 00181 { 00182 return(TRUE); 00183 } 00184 } 00185 return(FALSE); 00186 } 00187 00188 char MSD_lowIsAncestorAxis(APTYPE ancaptr, APTYPE desaptr) 00189 { 00190 GPTYPE gptr; 00191 00192 for (gptr = MSD_getGroupAxis(desaptr); gptr != GNIL; gptr = GrpParent(gptr)) 00193 { 00194 if (GrpGAxs(gptr) == ancaptr) 00195 { 00196 return(TRUE); 00197 } 00198 } 00199 return(FALSE); 00200 } 00201 00202 GPTYPE MSD_getGroupAxis(APTYPE axis) 00203 { 00204 if (AxsType(axis) == SOLID) 00205 { 00206 return(SolGroup(AxsASolid(axis))); 00207 } 00208 if (AxsType(axis) == GROUP) 00209 { 00210 return(AxsAGroup(axis)); 00211 } 00212 return(GNIL); 00213 }