Skip to content

Commit

Permalink
split label functions into shared
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeOShannessy committed Aug 13, 2024
1 parent c092dc9 commit 3236810
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 243 deletions.
2 changes: 1 addition & 1 deletion Build/smokeview/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bin = .

csrc = callbacks.c camera.c color2rgb.c readimage.c readgeom.c readobject.c colortimebar.c compress.c csphere.c dmalloc.c \
drawGeometry.c file_util.c getdata.c getdatabounds.c getdatacolors.c glew.c \
histogram.c infoheader.c \
histogram.c infoheader.c readlabel.c \
IOboundary.c IOgeometry.c IOhvac.c IOiso.c IOobjects.c IOpart.c IOplot2d.c IOplot3d.c \
IOscript.c IOshooter.c IOslice.c IOsmoke.c IOtour.c IOvolsmoke.c IOwui.c IOzone.c IOframe.o isobox.c \
main.c md5.c menus.c output.c readsmv.c renderhtml.c renderimage.c scontour2d.c sha1.c \
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ add_executable(smokeview
Source/shared/readimage.c
Source/shared/readgeom.c
Source/shared/readobject.c
Source/shared/readlabel.c
Source/smokeview/colortable.c
Source/smokeview/command_args.c
)
Expand Down
208 changes: 208 additions & 0 deletions Source/shared/readlabel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#include "options.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "MALLOCC.h"
#include "contourdefs.h"
#include "histogram.h"
#include "isodefs.h"
#include "smokeviewdefs.h"
#include "string_util.h"
#include "structures.h"

#include "readobject.h"

#include "readlabel.h"

/* ------------------ LabelGet ------------------------ */

labeldata *LabelGet(labels_collection *labelscoll, char *name) {
labeldata *thislabel;

if(name == NULL) return NULL;
for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL;
thislabel = thislabel->next) {
if(strcmp(thislabel->name, name) == 0) return thislabel;
}
return NULL;
}

void LabelInsertBefore(labeldata *listlabel, labeldata *label) {
labeldata *prev, *next;

prev = listlabel->prev;
next = listlabel;
prev->next = label;
next->prev = label;
label->prev = prev;
label->next = next;
}

void LabelInsertAfter(labeldata *listlabel, labeldata *label) {
labeldata *prev, *next;

prev = listlabel;
next = listlabel->next;
prev->next = label;
next->prev = label;
label->prev = prev;
label->next = next;
}

labeldata *LabelInsert(labels_collection *labelscoll, labeldata *labeltemp) {
labeldata *newlabel, *thislabel;
labeldata *firstuserptr, *lastuserptr;

NewMemory((void **)&newlabel, sizeof(labeldata));
memcpy(newlabel, labeltemp, sizeof(labeldata));

thislabel = LabelGet(labelscoll, newlabel->name);
if(thislabel != NULL) {
LabelInsertAfter(thislabel->prev, newlabel);
return newlabel;
}

firstuserptr = labelscoll->label_first_ptr->next;
if(firstuserptr == labelscoll->label_last_ptr) firstuserptr = NULL;

lastuserptr = labelscoll->label_last_ptr->prev;
if(lastuserptr == labelscoll->label_first_ptr) lastuserptr = NULL;

if(firstuserptr != NULL && strcmp(newlabel->name, firstuserptr->name) < 0) {
LabelInsertBefore(firstuserptr, newlabel);
return newlabel;
}
if(lastuserptr != NULL && strcmp(newlabel->name, lastuserptr->name) > 0) {
LabelInsertAfter(lastuserptr, newlabel);
return newlabel;
}
if(firstuserptr == NULL && lastuserptr == NULL) {
LabelInsertAfter(labelscoll->label_first_ptr, newlabel);
return newlabel;
}
for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL;
thislabel = thislabel->next) {
labeldata *nextlabel;

nextlabel = thislabel->next;
if(strcmp(thislabel->name, newlabel->name) < 0 &&
strcmp(newlabel->name, nextlabel->name) < 0) {
LabelInsertAfter(thislabel, newlabel);
return newlabel;
}
}
return NULL;
}

/* ------------------ LabelDelete ------------------------ */

void LabelDelete(labeldata *label) {
labeldata *prev, *next;

prev = label->prev;
next = label->next;
CheckMemory;
FREEMEMORY(label);
prev->next = next;
next->prev = prev;
}

/* ------------------ LabelCopy ------------------------ */

void LabelCopy(labeldata *label_to, labeldata *label_from) {
labeldata *prev, *next;

prev = label_to->prev;
next = label_to->next;
memcpy(label_to, label_from, sizeof(labeldata));
label_to->prev = prev;
label_to->next = next;
}

/* ------------------ LabelResort ------------------------ */

void LabelResort(labels_collection *labelscoll, labeldata *label) {
labeldata labelcopy;

CheckMemory;
memcpy(&labelcopy, label, sizeof(labeldata));
CheckMemory;
LabelDelete(label);
LabelInsert(labelscoll, &labelcopy);
}

/* ------------------ LabelPrint ------------------------ */

void LabelPrint(labeldata *label_first_ptr) {
labeldata *thislabel;
float *xyz;

for(thislabel = label_first_ptr->next; thislabel->next != NULL;
thislabel = thislabel->next) {
xyz = thislabel->xyz;
PRINTF("label: %s position: %f %f %f\n", thislabel->name, xyz[0], xyz[1],
xyz[2]);
}
}

/* ------------------ LabelNext ------------------------ */

labeldata *LabelNext(labels_collection *labelscoll, labeldata *label) {
labeldata *thislabel;

if(label == NULL) return NULL;
if(labelscoll->label_first_ptr->next->next == NULL) return NULL;
for(thislabel = label->next; thislabel != label;
thislabel = thislabel->next) {
if(thislabel->next == NULL) thislabel = labelscoll->label_first_ptr->next;
if(thislabel->labeltype == TYPE_SMV) continue;
return thislabel;
}
return NULL;
}

/* ------------------ LabelPrevious ------------------------ */

labeldata *LabelPrevious(labels_collection *labelscoll, labeldata *label) {
labeldata *thislabel;

if(label == NULL) return NULL;
if(labelscoll->label_last_ptr->prev->prev == NULL) return NULL;
for(thislabel = label->prev; thislabel != label;
thislabel = thislabel->prev) {
if(thislabel->prev == NULL) thislabel = labelscoll->label_last_ptr->prev;
if(thislabel->labeltype == TYPE_SMV) continue;
return thislabel;
}
return NULL;
}

/* ------------------ LabelInit ------------------------ */

int LabelInit(labels_collection *labelscoll, labeldata *gl) {
labeldata *thislabel;

for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL;
thislabel = thislabel->next) {
if(thislabel->labeltype == TYPE_SMV) continue;
LabelCopy(gl, thislabel);
return 1;
}
return 0;
}

/* ------------------ LabelGetNUserLabels ------------------------ */

int LabelGetNUserLabels(labels_collection *labelscoll) {
int count = 0;
labeldata *thislabel;

for(thislabel = labelscoll->label_first_ptr->next; thislabel->next != NULL;
thislabel = thislabel->next) {
if(thislabel->labeltype == TYPE_INI) count++;
}
return count;
}
26 changes: 26 additions & 0 deletions Source/shared/readlabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef READLABEL_H_DEFINED
#define READLABEL_H_DEFINED

/**
* @brief A collection of labels. At it's core this collection
* contains a linked list, but also an array of pointers into that linked list.
*
*/
typedef struct {
labeldata label_first;
labeldata label_last;
labeldata *label_first_ptr;
labeldata *label_last_ptr;
} labels_collection;

EXTERNCPP labeldata *LabelGet(labels_collection *labelscoll, char *name);
EXTERNCPP labeldata *LabelInsert(labels_collection *labelscoll,
labeldata *labeltemp);

EXTERNCPP int LabelGetNUserLabels(labels_collection *labelscoll);
EXTERNCPP labeldata *LabelPrevious(labels_collection *labelscoll,
labeldata *label);
EXTERNCPP labeldata *LabelNext(labels_collection *labelscoll, labeldata *label);
EXTERNCPP void LabelCopy(labeldata *label_to, labeldata *label_from);
EXTERNCPP void LabelDelete(labeldata *label);
#endif
33 changes: 17 additions & 16 deletions Source/smokeview/glui_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <math.h>

#include "smokeviewvars.h"
#include "readlabel.h"

GLUI *glui_labels=NULL;

Expand Down Expand Up @@ -311,7 +312,7 @@ void DisplayRolloutCB(int var){
/* ------------------ UpdateGluiLabelText ------------------------ */

void UpdateGluiLabelText(void){
if(LabelGetNUserLabels()>0){
if(LabelGetNUserLabels(&labelscoll)>0){
labeldata *gl;

gl=&LABEL_local;
Expand Down Expand Up @@ -394,15 +395,15 @@ void TextLabelsCB(int var){
updatemenu = 1;
break;
case LB_UPDATE:
for(thislabel = label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
for(thislabel = labelscoll.label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
if(thislabel->glui_id < 0)continue;
LIST_LB_labels->delete_item(thislabel->glui_id);
}
strcpy(LABEL_global_ptr->name, gl->name);
//LabelResort(LABEL_global_ptr);

count = 0;
for(thislabel = label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
for(thislabel = labelscoll.label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
if(thislabel->labeltype == TYPE_SMV)continue;
thislabel->glui_id = count;
LIST_LB_labels->add_item(count++, thislabel->name);
Expand All @@ -418,8 +419,8 @@ void TextLabelsCB(int var){
memcpy(&LABEL_global_ptr->useforegroundcolor, &gl->useforegroundcolor, sizeof(int));
break;
case LB_PREVIOUS:
new_label = LabelGet(LIST_LB_labels->curr_text);
new_label = LabelPrevious(new_label);
new_label = LabelGet(&labelscoll,LIST_LB_labels->curr_text);
new_label = LabelPrevious(&labelscoll,new_label);
if(new_label == NULL)break;
LABEL_global_ptr = new_label;
if(new_label != NULL){
Expand All @@ -428,8 +429,8 @@ void TextLabelsCB(int var){
}
break;
case LB_NEXT:
new_label = LabelGet(LIST_LB_labels->curr_text);
new_label = LabelNext(new_label);
new_label = LabelGet(&labelscoll,LIST_LB_labels->curr_text);
new_label = LabelNext(&labelscoll,new_label);
if(new_label == NULL)break;
LABEL_global_ptr = new_label;
if(new_label != NULL){
Expand All @@ -438,7 +439,7 @@ void TextLabelsCB(int var){
}
break;
case LB_LIST:
new_label = LabelGet(LIST_LB_labels->curr_text);
new_label = LabelGet(&labelscoll,LIST_LB_labels->curr_text);
LABEL_global_ptr = new_label;
if(new_label != NULL){
LabelCopy(gl, new_label);
Expand All @@ -447,7 +448,7 @@ void TextLabelsCB(int var){
break;
case LB_ADD:
updatemenu = 1;
if(LabelGetNUserLabels() > 0){
if(LabelGetNUserLabels(&labelscoll) > 0){
strcpy(name, "copy of ");
strcat(name, gl->name);
strcpy(gl->name, name);
Expand All @@ -456,13 +457,13 @@ void TextLabelsCB(int var){
gl = &LABEL_default;
}
gl->labeltype = TYPE_INI;
for(thislabel = label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
for(thislabel = labelscoll.label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
if(thislabel->glui_id < 0)continue;
LIST_LB_labels->delete_item(thislabel->glui_id);
}
LabelInsert(gl);
LabelInsert(&labelscoll, gl);
count = 0;
for(thislabel = label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
for(thislabel = labelscoll.label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
if(thislabel->labeltype == TYPE_SMV)continue;
thislabel->glui_id = count;
LIST_LB_labels->add_item(count++, thislabel->name);
Expand All @@ -471,16 +472,16 @@ void TextLabelsCB(int var){
break;
case LB_DELETE:
strcpy(name, LIST_LB_labels->curr_text);
for(thislabel = label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
for(thislabel = labelscoll.label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
if(thislabel->glui_id < 0)continue;
LIST_LB_labels->delete_item(thislabel->glui_id);
}
thislabel = LabelGet(name);
thislabel = LabelGet(&labelscoll,name);
if(thislabel != NULL){
LabelDelete(thislabel);
}
count = 0;
for(thislabel = label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
for(thislabel = labelscoll.label_first_ptr->next;thislabel->next != NULL;thislabel = thislabel->next){
if(thislabel->labeltype == TYPE_SMV)continue;
thislabel->glui_id = count;
LIST_LB_labels->add_item(count++, thislabel->name);
Expand Down Expand Up @@ -1069,7 +1070,7 @@ extern "C" void GLUIDisplaySetup(int main_window){
labeldata *thislabel;
int count=0;

for(thislabel=label_first_ptr->next;thislabel->next!=NULL;thislabel=thislabel->next){
for(thislabel=labelscoll.label_first_ptr->next;thislabel->next!=NULL;thislabel=thislabel->next){
if(thislabel->labeltype==TYPE_SMV){
thislabel->glui_id=-1;
continue;
Expand Down
Loading

0 comments on commit 3236810

Please sign in to comment.