/*****************************************************************************1*2* Elmer, A Finite Element Software for Multiphysical Problems3*4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License8* as published by the Free Software Foundation; either version 29* of the License, or (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program (in file fem/GPL-2); if not, write to the18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19* Boston, MA 02110-1301, USA.20*21*****************************************************************************/2223/*******************************************************************************24*25* Objects main module & utilities26*27*******************************************************************************28*29* Author: Juha Ruokolainen30*31* Address: CSC - IT Center for Science Ltd.32* Keilaranta 14, P.O. BOX 40533* 02101 Espoo, Finland34* Tel. +358 0 457 272335* Telefax: +358 0 457 230236* EMail: [email protected]37*38* Date: 2 Oct 199539*40* Modified by:41*42* Date of modification:43*44******************************************************************************/4546#define MODULE_OBJECTS4748#include "../elmerpost.h"4950/*******************************************************************************51*52* Name: obj_initialize_object53*54* Purpose: Initialize object to default values55*56* Parameters:57*58* Input: none59*60* Output: (object_t *)61*62* Return value: void63*64******************************************************************************/65void obj_object_initialize( object_t *object )66{67int i;6869obj_init_transform( &object->Transform );70for( i=0; i<6;i++ ) object->ClipPlane[i] = -1;71PiDiv180 = acos(0.0) / 90.0;72}7374/*******************************************************************************75*76* Name: obj_new77*78* Purpose: Create a new object. Internal only.79*80* Parameters:81*82* Input: Name of the object to create.83*84* Output: none85*86* Return value: (object_t *)87*88******************************************************************************/89object_t *obj_new(char *name)90{91object_t *object = calloc(1,sizeof(object_t));9293if ( !object )94{95fprintf( stderr, "object_new: FATAL: can't allocate a few bytes of memory.\n" );96return NULL;97}9899if ( name )100{101if ( !(object->Name = malloc( strlen(name)+1 ) ) )102{103fprintf( stderr, "object_new: FATAL: can't allocate a few bytes of memory.\n" );104free( object );105return NULL;106}107108strcpy( object->Name,name );109}110111obj_object_initialize( object );112113return object;114}115116/*******************************************************************************117*118* Name: obj_add_object119*120* Purpose: Add a new object to list of objects given.121*122* Parameters:123*124* Input: (object_t *) input list125* (char *) name of the object to create126*127* Output: (object_t *) is modified128*129* Return value: pointer to (object_t *), the new entry in the list.130*131******************************************************************************/132object_t *obj_add_object( object_t *object,char *name )133{134object_t *new = obj_new(name);135136if ( !new ) return NULL;137138if ( object )139{140new->Id = 1;141while( object->Next ) { object = object->Next; new->Id++; }142object->Next = new;143}144145return new;146}147148/*******************************************************************************149*150* Name: obj_find151*152* Purpose: Return pointer to an object with given name if any.153*154* Parameters:155*156* Input: (object_t *) input list of objects157* (char *) name of the object to find158*159* Output: none160*161* Return value: pointer to (object_t *) if found, NULL otherwise162*163******************************************************************************/164object_t *obj_find( object_t *object,char *name )165{166while( object )167{168if ( strcmp( object->Name, name ) == 0 ) return object;169object = object->Next;170}171172return NULL;173}174175/*******************************************************************************176*177* Name: obj_display_list178*179* Purpose: Display list of objects given.180*181* Parameters:182*183* Input: (object_t *) input list of objects184*185* Output: graphics186*187* Return value: if mouse interaction is going on and too slow FALSE,188* otherwise true189*190******************************************************************************/191int obj_display_list( object_t *object,double t )192{193extern double XMin,XMax,YMin,YMax,ZMin,ZMax;194int i;195void gra_clip_plane(), gra_bbox(), obj_set_matrix(), gra_disable_clip();196197for( ; object != NULL; object = object->Next )198{199gra_push_matrix();200obj_set_matrix( object );201202for( i=0; i<6; i++ )203if ( object->ClipPlane[i] >= 0 )204gra_clip_plane( object->ClipPlane[i],object->ClipEquation[i] );205206if ( user_hook_object_before )207(*user_hook_object_before)208(209GlobalPass,object->Geometry,object->ElementModel,object->VisualList,t210);211212if ( epMouseDown && epMouseDownTakesTooLong > 3 )213{214gra_bbox( XMin,XMax,YMin,YMax,ZMin,ZMax );215}216else if ( !vis_display_list( object->Geometry,object->ElementModel,object->VisualList,t ) )217{218gra_pop_matrix();219return FALSE;220}221222if ( user_hook_object_after )223(*user_hook_object_after)224(225GlobalPass,object->Geometry,object->ElementModel,object->VisualList,t226);227228for( i=0; i<6; i++ )229if ( object->ClipPlane[i] >= 0 ) gra_disable_clip( object->ClipPlane[i] );230231232gra_pop_matrix();233}234235return TRUE;236}237238239