00001 /* 00002 PROJETO USPDesigner 00003 MODULO: DIS (Hidden Line Elimination) 00004 Copyright (C) 1989 a 2008, Marcos Tsuzuki, All rights reserved 00005 Universidade de Sao Paulo, EPUSP-PMR 00006 00007 NOME DO ARQUIVO: disccolr.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 "mensagem.h" 00043 #include "memvirtu.h" 00044 #include "lowparam.h" 00045 #include "lowmacro.h" 00046 #include "lowsolid.h" 00047 #include "hiegroup.h" 00048 #include "disdispl.h" 00049 #include "genfunc_.h" 00050 #include "gphgraph.h" 00051 #include "mancommd.h" 00052 #include "eulerops.h" 00053 00054 extern int MaxColors; 00055 00056 void MSD_execColor(void) 00057 { 00058 int ip; 00059 char name1[12]; 00060 int i1; 00061 00062 for (ip = 0; ip == 0;) 00063 { 00064 switch (optin()) 00065 { 00066 case 'o': 00067 if (2 == sscanf(restbuf, "%s %d", name1, &i1)) 00068 { 00069 MSD_highNameSolidColor(name1, i1); 00070 ip = 1; 00071 } 00072 break; 00073 00074 case 'g': 00075 if (2 == sscanf(restbuf, "%s %d", name1, &i1)) 00076 { 00077 MSD_highNameGroupColor(name1, i1); 00078 ip = 1; 00079 } 00080 break; 00081 00082 case 'd': 00083 if (1 == sscanf(restbuf, "%d", &i1)) 00084 { 00085 MSD_lowSetDefaultColor(i1); 00086 ip = 1; 00087 } 00088 break; 00089 00090 case 'f': 00091 if (1 == sscanf(restbuf, "%d", &i1)) 00092 { 00093 MSD_lowSetFrameColor(i1); 00094 ip = 1; 00095 } 00096 break; 00097 } 00098 if (ip == 0) 00099 { 00100 printf("-dfgo [Objeto/Grupo] cor\n"); 00101 if (!lineins("? ")) 00102 { 00103 return; 00104 } 00105 } 00106 } 00107 } 00108 00109 int MSD_lowSetFrameColor(int color) 00110 { 00111 if ((color > -1) && (color < MaxColors)) 00112 { 00113 framecol = color; 00114 return(TRUE); 00115 } 00116 fprintf(stderr, MEN_CorInvalida, NAM_SetFrameColor); 00117 return(FALSE); 00118 } 00119 00120 int MSD_lowSetDefaultColor(int color) 00121 { 00122 if ((color > -2) && (color < MaxColors)) 00123 { 00124 defltcol = color; 00125 return(TRUE); 00126 } 00127 fprintf(stderr, MEN_CorInvalida, NAM_SetDefaultColor); 00128 return(FALSE); 00129 } 00130 00131 /* 00132 * int MSD_highNameSetElementColor(char *name, int color) 00133 * { 00134 * if (color < -1 || color > MaxColors - 1) { 00135 * fprintf(stderr, MEN_CorInvalida, NAM_SetElementColor) ; 00136 * return(FALSE) ; 00137 * } 00138 * switch(MSD_getTypeByName(name)) { 00139 * case 'o': 00140 * return(MSD_highNameSetSolidColor(name, color)) ; 00141 * case 'g': 00142 * return(MSD_highNameSetGroupColor(name, color)) ; 00143 * } 00144 * fprintf(stderr, MEN_ElementoNaoEncontrado, NAM_SetElementColor, name) ; 00145 * return(FALSE) ; 00146 * } 00147 * 00148 * int MSD_highNameSetSolidColor(char *name, int col) 00149 * { 00150 * SPTYPE optr ; 00151 * 00152 * if (col < -2 || col > MaxColors - 1) { 00153 * fprintf(stderr, MEN_CorInvalida, NAM_SetElementColor) ; 00154 * return(FALSE) ; 00155 * } 00156 * if ((optr = MSD_lowFindSolidByName(name)) != SNIL) 00157 * return(MSD_lowSetSolidColor(optr, col)) ; 00158 * fprintf(stderr, MEN_ElementoNaoEncontrado, NAM_SetElementColor, name) ; 00159 * return(FALSE) ; 00160 * } 00161 * 00162 * int MSD_lowSetSolidColor(SPTYPE optr, int col) 00163 * { 00164 * if (col < -2 || col > MaxColors - 1) { 00165 * fprintf(stderr, MEN_CorInvalida, NAM_SetElementColor) ; 00166 * return(FALSE) ; 00167 * } 00168 * SolColor(optr) = col ; 00169 * return(TRUE) ; 00170 * } 00171 * 00172 * int MSD_highNameSetGroupColor(char *name, int col) 00173 * { 00174 * GPTYPE gptr ; 00175 * 00176 * if (col < -2 || col > MaxColors - 1) { 00177 * fprintf(stderr, MEN_CorInvalida, NAM_SetElementColor) ; 00178 * return(FALSE) ; 00179 * } 00180 * if ((gptr = MSD_lowFindGroupByName(name)) != GNIL) 00181 * return(MSD_lowSetGroupColor(gptr, col)) ; 00182 * fprintf(stderr, MEN_ElementoNaoEncontrado, NAM_SetElementColor, name) ; 00183 * return(FALSE) ; 00184 * } 00185 * 00186 * int MSD_lowSetGroupColor(GPTYPE gptr, int col) 00187 * { 00188 * if (col < -2 || col > MaxColors - 1) { 00189 * fprintf(stderr, MEN_CorInvalida, NAM_SetElementColor) ; 00190 * return(FALSE) ; 00191 * } 00192 * GrpGColor(gptr) = col ; 00193 * return(TRUE) ; 00194 * } 00195 */ 00196 00197 int MSD_lowGetIntersectionColor(SPTYPE o1ptr, SPTYPE o2ptr) 00198 { 00199 int col1, col2; 00200 00201 col1 = MSD_lowGetSolidColor(o1ptr); 00202 col2 = MSD_lowGetSolidColor(o2ptr); 00203 return(col1 > col2 ? col1 : col2); 00204 } 00205 00206 int MSD_lowGetSolidColor(SPTYPE optr) 00207 { 00208 GPTYPE gptr; 00209 00210 if (SolColor(optr) > -1) 00211 { 00212 return(SolColor(optr)); 00213 } 00214 for (gptr = SolGroup(optr); gptr != GNIL; gptr = GrpParent(gptr)) 00215 { 00216 if (GrpGColor(gptr) > -1) 00217 { 00218 return(GrpGColor(gptr)); 00219 } 00220 } 00221 return(defltcol); 00222 }