From 7d7eed2b73a6664197a3a74dbef290fecc226d39 Mon Sep 17 00:00:00 2001 From: Jarrett Johnson Date: Tue, 10 Feb 2026 15:11:56 -0500 Subject: [PATCH] clang-format gadget module --- layer2/GadgetSet.cpp | 316 +++++++++---------- layer2/GadgetSet.h | 47 +-- layer2/ObjectGadget.cpp | 289 +++++++++-------- layer2/ObjectGadget.h | 42 +-- layer2/ObjectGadgetRamp.cpp | 611 ++++++++++++++++++------------------ layer2/ObjectGadgetRamp.h | 51 ++- 6 files changed, 693 insertions(+), 663 deletions(-) diff --git a/layer2/GadgetSet.cpp b/layer2/GadgetSet.cpp index a904084b2..6ce6f7e20 100644 --- a/layer2/GadgetSet.cpp +++ b/layer2/GadgetSet.cpp @@ -1,52 +1,52 @@ -/* +/* A* ------------------------------------------------------------------- B* This file contains source code for the PyMOL computer program -C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. +C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. D* ------------------------------------------------------------------- E* It is unlawful to modify or remove this copyright notice. F* ------------------------------------------------------------------- -G* Please see the accompanying LICENSE file for further information. +G* Please see the accompanying LICENSE file for further information. H* ------------------------------------------------------------------- I* Additional authors of this source file include: --* --* +-* +-* -* Z* ------------------------------------------------------------------- */ -#include"os_python.h" +#include "os_python.h" -#include"os_predef.h" -#include"os_std.h" +#include "os_predef.h" +#include "os_std.h" -#include"Base.h" -#include"MemoryDebug.h" -#include"Err.h" -#include"Scene.h" -#include"GadgetSet.h" -#include"ObjectGadget.h" -#include"Color.h" -#include"PConv.h" -#include"main.h" -#include"CGO.h" -#include"ShaderMgr.h" -#include"Ray.h" +#include "Base.h" +#include "CGO.h" +#include "Color.h" +#include "Err.h" +#include "GadgetSet.h" +#include "MemoryDebug.h" +#include "ObjectGadget.h" +#include "PConv.h" +#include "Ray.h" +#include "Scene.h" +#include "ShaderMgr.h" +#include "main.h" -int GadgetSetGetVertex(const GadgetSet * I, int index, int base, float *v) +int GadgetSetGetVertex(const GadgetSet* I, int index, int base, float* v) { int ok = true; float *v0, *v1; - if(index < I->NCoord) { + if (index < I->NCoord) { v0 = I->Coord + 3 * index; - if(base < 0) { + if (base < 0) { copy3f(v0, v); - if(index){ + if (index) { add3f(I->Coord, v, v); } - } else if(base < I->NCoord) { + } else if (base < I->NCoord) { v1 = I->Coord + 3 * base; add3f(v1, v0, v); - if(index) + if (index) add3f(I->Coord, v, v); } else { ok = false; @@ -56,26 +56,26 @@ int GadgetSetGetVertex(const GadgetSet * I, int index, int base, float *v) return (ok); } -int GadgetSetSetVertex(GadgetSet * I, int index, int base, const float *v) +int GadgetSetSetVertex(GadgetSet* I, int index, int base, const float* v) { int ok = true; float *v0, *v1; - if(index < I->NCoord) { + if (index < I->NCoord) { v0 = I->Coord + 3 * index; - if(base < 0) { + if (base < 0) { copy3f(v, v0); - if(index){ + if (index) { subtract3f(v0, I->Coord, v0); } else { - if (I->offsetPtOP) - copy3f(v0, &I->StdCGO->op[I->offsetPtOP]); - if (I->offsetPtOPick) - copy3f(v0, &I->PickCGO->op[I->offsetPtOPick]); + if (I->offsetPtOP) + copy3f(v0, &I->StdCGO->op[I->offsetPtOP]); + if (I->offsetPtOPick) + copy3f(v0, &I->PickCGO->op[I->offsetPtOPick]); } - } else if(base < I->NCoord) { + } else if (base < I->NCoord) { v1 = I->Coord + 3 * base; subtract3f(v, v1, v0); - if(index) + if (index) subtract3f(v0, I->Coord, v0); } else { ok = false; @@ -85,64 +85,66 @@ int GadgetSetSetVertex(GadgetSet * I, int index, int base, const float *v) return (ok); } -int GadgetSetFromPyList(PyMOLGlobals * G, PyObject * list, GadgetSet ** gs, int version) +int GadgetSetFromPyList( + PyMOLGlobals* G, PyObject* list, GadgetSet** gs, int version) { int ok = true; - GadgetSet *I = nullptr; - PyObject *tmp = nullptr; + GadgetSet* I = nullptr; + PyObject* tmp = nullptr; - if(*gs) { + if (*gs) { delete *gs; *gs = nullptr; } - if(list == Py_None) { /* allow None for GSet */ + if (list == Py_None) { /* allow None for GSet */ *gs = nullptr; } else { - if(ok) + if (ok) I = GadgetSetNew(G); - if(ok) + if (ok) ok = (I != nullptr); - if(ok) + if (ok) ok = (list != nullptr); - if(ok) + if (ok) ok = PyList_Check(list); /* TO SUPPORT BACKWARDS COMPATIBILITY... Always check ll when adding new PyList_GetItem's */ - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 0), &I->NCoord); - if(ok && I->NCoord) + if (ok && I->NCoord) ok = PConvPyListToFloatVLA(PyList_GetItem(list, 1), &I->Coord); - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 2), &I->NNormal); - if(ok && I->NNormal) + if (ok && I->NNormal) ok = PConvPyListToFloatVLA(PyList_GetItem(list, 3), &I->Normal); - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 4), &I->NColor); - if(ok && I->NColor) + if (ok && I->NColor) ok = PConvPyListToFloatVLA(PyList_GetItem(list, 5), &I->Color); - if(ok) + if (ok) ok = ((tmp = PyList_GetItem(list, 6)) != nullptr); - if(ok && (tmp != Py_None)) + if (ok && (tmp != Py_None)) ok = ((I->ShapeCGO = CGONewFromPyList(I->G, tmp, version)) != nullptr); - if(ok) + if (ok) ok = ((tmp = PyList_GetItem(list, 7)) != nullptr); - if(ok && (tmp != Py_None)) - ok = ((I->PickShapeCGO = CGONewFromPyList(I->G, tmp, version)) != nullptr); + if (ok && (tmp != Py_None)) + ok = + ((I->PickShapeCGO = CGONewFromPyList(I->G, tmp, version)) != nullptr); - if(ok && I->ShapeCGO) - if(CGOCheckForText(I->ShapeCGO)) { + if (ok && I->ShapeCGO) + if (CGOCheckForText(I->ShapeCGO)) { CGOPreloadFonts(I->ShapeCGO); } - if(!ok) { - if(I) + if (!ok) { + if (I) delete I; } else { *gs = I; @@ -152,61 +154,61 @@ int GadgetSetFromPyList(PyMOLGlobals * G, PyObject * list, GadgetSet ** gs, int return (ok); } -PyObject *GadgetSetAsPyList(GadgetSet * I, bool incl_cgos) +PyObject* GadgetSetAsPyList(GadgetSet* I, bool incl_cgos) { - PyObject *result = nullptr; + PyObject* result = nullptr; - if(I) { + if (I) { result = PyList_New(8); PyList_SetItem(result, 0, PyInt_FromLong(I->NCoord)); - if(I->NCoord) { - PyList_SetItem(result, 1, PConvFloatArrayToPyList(I->Coord, I->NCoord * 3)); + if (I->NCoord) { + PyList_SetItem( + result, 1, PConvFloatArrayToPyList(I->Coord, I->NCoord * 3)); } else { PyList_SetItem(result, 1, PConvAutoNone(nullptr)); } PyList_SetItem(result, 2, PyInt_FromLong(I->NNormal)); - if(I->NNormal) { - PyList_SetItem(result, 3, PConvFloatArrayToPyList(I->Normal, I->NNormal * 3)); + if (I->NNormal) { + PyList_SetItem( + result, 3, PConvFloatArrayToPyList(I->Normal, I->NNormal * 3)); } else { PyList_SetItem(result, 3, PConvAutoNone(nullptr)); } PyList_SetItem(result, 4, PyInt_FromLong(I->NColor)); - if(I->NColor) { + if (I->NColor) { PyList_SetItem(result, 5, PConvFloatArrayToPyList(I->Color, I->NColor)); } else { PyList_SetItem(result, 5, PConvAutoNone(nullptr)); } - if(incl_cgos && I->ShapeCGO) { + if (incl_cgos && I->ShapeCGO) { PyList_SetItem(result, 6, CGOAsPyList(I->ShapeCGO)); } else { PyList_SetItem(result, 6, PConvAutoNone(nullptr)); } - if(incl_cgos && I->PickShapeCGO) { + if (incl_cgos && I->PickShapeCGO) { PyList_SetItem(result, 7, CGOAsPyList(I->PickShapeCGO)); } else { PyList_SetItem(result, 7, PConvAutoNone(nullptr)); } - } return (PConvAutoNone(result)); } - /*========================================================================*/ -int GadgetSetGetExtent(GadgetSet * I, float *mn, float *mx) +int GadgetSetGetExtent(GadgetSet* I, float* mn, float* mx) { - float *v; + float* v; int a; v = I->Coord; - for(a = 0; a < I->NCoord; a++) { + for (a = 0; a < I->NCoord; a++) { min3f(v, mn, mn); max3f(v, mx, mx); v += 3; @@ -214,38 +216,33 @@ int GadgetSetGetExtent(GadgetSet * I, float *mn, float *mx) return (I->NCoord); } - /*========================================================================*/ -void GadgetSet::invalidateRep(cRep_t type, cRepInv_t level) -{ -} - +void GadgetSet::invalidateRep(cRep_t type, cRepInv_t level) {} /*========================================================================*/ void GadgetSet::update() { - GadgetSet * I = this; - if(I->StdCGO) { + GadgetSet* I = this; + if (I->StdCGO) { CGOFree(I->StdCGO); I->offsetPtOP = 0; I->StdCGO = nullptr; } - if(I->PickCGO) { + if (I->PickCGO) { CGOFree(I->PickCGO); I->offsetPtOPick = 0; I->PickCGO = nullptr; } } - /*========================================================================*/ -void GadgetSet::render(RenderInfo * info) +void GadgetSet::render(RenderInfo* info) { - GadgetSet * I = this; + GadgetSet* I = this; const RenderPass pass = info->pass; - CRay *ray = info->ray; + CRay* ray = info->ray; auto pick = info->pick; - const float *color; + const float* color; PickContext context; context.object = I->Obj; @@ -253,66 +250,69 @@ void GadgetSet::render(RenderInfo * info) color = ColorGet(I->G, I->Obj->Color); - if(pass == RenderPass::Transparent || ray || pick) { - PyMOLGlobals *G = I->G; + if (pass == RenderPass::Transparent || ray || pick) { + PyMOLGlobals* G = I->G; - if(ray) { - if(I->ShapeCGO){ - float mat[16] = { 1.f, 0.f, 0.f, I->Coord[0], - 0.f, 1.f, 0.f, I->Coord[1], - 0.f, 0.f, 1.f, I->Coord[2], - 0.f, 0.f, 0.f, 1.f }; - RayPushTTT(ray); - RaySetTTT(ray, true, mat); /* Used to set the ray-tracing matrix, - this works, but is there another way to do this? */ - CGORenderRay(I->ShapeCGO, ray, info, color, nullptr, I->Obj->Setting.get(), nullptr); - RayPopTTT(ray); + if (ray) { + if (I->ShapeCGO) { + float mat[16] = {1.f, 0.f, 0.f, I->Coord[0], 0.f, 1.f, 0.f, I->Coord[1], + 0.f, 0.f, 1.f, I->Coord[2], 0.f, 0.f, 0.f, 1.f}; + RayPushTTT(ray); + RaySetTTT(ray, true, + mat); /* Used to set the ray-tracing matrix, + this works, but is there another way to do this? */ + CGORenderRay(I->ShapeCGO, ray, info, color, nullptr, + I->Obj->Setting.get(), nullptr); + RayPopTTT(ray); } - } else if(G->HaveGUI && G->ValidContext) { + } else if (G->HaveGUI && G->ValidContext) { short use_shader = (short) SettingGetGlobal_b(I->G, cSetting_use_shaders); - if(pick) { - if (!I->PickCGO && I->PickShapeCGO){ - CGO *convertcgo; - int ok = true; - convertcgo = CGOCombineBeginEnd(I->PickShapeCGO, 0); - CHECKOK(ok, convertcgo); - if (ok){ - if (use_shader){ - CGO *tmpCGO; - tmpCGO = CGOOptimizeToVBOIndexedNoShader(convertcgo, 0); - I->PickCGO = CGONew(G); - CGODisable(I->PickCGO, GL_DEPTH_TEST); - CGOEnable(I->PickCGO, GL_RAMP_SHADER); - I->offsetPtOPick = CGOUniform3f(I->PickCGO, RAMP_OFFSETPT, (const float*)I->Coord); - CGOAppendNoStop(I->PickCGO, tmpCGO); - CGOFreeWithoutVBOs(tmpCGO); - CGODisable(I->PickCGO, GL_RAMP_SHADER); - CGOEnable(I->PickCGO, GL_DEPTH_TEST); - CGOStop(I->PickCGO); - I->PickCGO->use_shader = true; - CGOFree(convertcgo); - } else { - I->PickCGO = convertcgo; - } - } else { - CGOFree(convertcgo); - } - } - if(I->PickCGO) { - if (use_shader){ - CGORenderPicking(I->PickCGO, info, &context, I->Obj->Setting.get(), nullptr); + if (pick) { + if (!I->PickCGO && I->PickShapeCGO) { + CGO* convertcgo; + int ok = true; + convertcgo = CGOCombineBeginEnd(I->PickShapeCGO, 0); + CHECKOK(ok, convertcgo); + if (ok) { + if (use_shader) { + CGO* tmpCGO; + tmpCGO = CGOOptimizeToVBOIndexedNoShader(convertcgo, 0); + I->PickCGO = CGONew(G); + CGODisable(I->PickCGO, GL_DEPTH_TEST); + CGOEnable(I->PickCGO, GL_RAMP_SHADER); + I->offsetPtOPick = CGOUniform3f( + I->PickCGO, RAMP_OFFSETPT, (const float*) I->Coord); + CGOAppendNoStop(I->PickCGO, tmpCGO); + CGOFreeWithoutVBOs(tmpCGO); + CGODisable(I->PickCGO, GL_RAMP_SHADER); + CGOEnable(I->PickCGO, GL_DEPTH_TEST); + CGOStop(I->PickCGO); + I->PickCGO->use_shader = true; + CGOFree(convertcgo); + } else { + I->PickCGO = convertcgo; + } + } else { + CGOFree(convertcgo); + } + } + if (I->PickCGO) { + if (use_shader) { + CGORenderPicking( + I->PickCGO, info, &context, I->Obj->Setting.get(), nullptr); #ifndef PURE_OPENGL_ES_2 - } else { - glDisable(GL_DEPTH_TEST); - glTranslatef(I->Coord[0],I->Coord[1],I->Coord[2]); - CGORenderPicking(I->PickShapeCGO, info, &context, I->Obj->Setting.get(), nullptr); - glTranslatef(-I->Coord[0],-I->Coord[1],-I->Coord[2]); - glEnable(GL_DEPTH_TEST); + } else { + glDisable(GL_DEPTH_TEST); + glTranslatef(I->Coord[0], I->Coord[1], I->Coord[2]); + CGORenderPicking(I->PickShapeCGO, info, &context, + I->Obj->Setting.get(), nullptr); + glTranslatef(-I->Coord[0], -I->Coord[1], -I->Coord[2]); + glEnable(GL_DEPTH_TEST); #endif - } + } } } else { - if (!I->StdCGO && I->ShapeCGO){ + if (!I->StdCGO && I->ShapeCGO) { if (!use_shader) { I->StdCGO = CGOCombineBeginEnd(I->ShapeCGO); assert(!I->StdCGO->has_begin_end); @@ -329,41 +329,41 @@ void GadgetSet::render(RenderInfo * info) assert(I->StdCGO->use_shader); assert(!I->StdCGO->has_begin_end); } - } - if(I->StdCGO) { - if (use_shader){ - if (color) - CGORender(I->StdCGO, nullptr, I->Obj->Setting.get(), nullptr, info, nullptr); + } + if (I->StdCGO) { + if (use_shader) { + if (color) + CGORender(I->StdCGO, nullptr, I->Obj->Setting.get(), nullptr, + info, nullptr); #ifndef PURE_OPENGL_ES_2 - } else { - glDisable(GL_DEPTH_TEST); - glTranslatef(I->Coord[0],I->Coord[1],I->Coord[2]); - CGORender(I->ShapeCGO, nullptr, I->Obj->Setting.get(), nullptr, info, nullptr); - glTranslatef(-I->Coord[0],-I->Coord[1],-I->Coord[2]); - glEnable(GL_DEPTH_TEST); + } else { + glDisable(GL_DEPTH_TEST); + glTranslatef(I->Coord[0], I->Coord[1], I->Coord[2]); + CGORender(I->ShapeCGO, nullptr, I->Obj->Setting.get(), nullptr, + info, nullptr); + glTranslatef(-I->Coord[0], -I->Coord[1], -I->Coord[2]); + glEnable(GL_DEPTH_TEST); #endif - } + } } } } } } - /*========================================================================*/ -GadgetSet *GadgetSetNew(PyMOLGlobals * G) +GadgetSet* GadgetSetNew(PyMOLGlobals* G) { auto I = new GadgetSet(); I->G = G; return (I); } - /*========================================================================*/ GadgetSet::~GadgetSet() { - GadgetSet * I = this; - if(I) { + GadgetSet* I = this; + if (I) { CGOFree(I->PickCGO); CGOFree(I->PickShapeCGO); CGOFree(I->StdCGO); diff --git a/layer2/GadgetSet.h b/layer2/GadgetSet.h index f4dc9db14..3cd59d305 100644 --- a/layer2/GadgetSet.h +++ b/layer2/GadgetSet.h @@ -1,23 +1,23 @@ -/* +/* A* ------------------------------------------------------------------- B* This file contains source code for the PyMOL computer program -C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. +C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. D* ------------------------------------------------------------------- E* It is unlawful to modify or remove this copyright notice. F* ------------------------------------------------------------------- -G* Please see the accompanying LICENSE file for further information. +G* Please see the accompanying LICENSE file for further information. H* ------------------------------------------------------------------- I* Additional authors of this source file include: --* --* +-* +-* -* Z* ------------------------------------------------------------------- */ #ifndef _H_GadgetSet #define _H_GadgetSet -#include"Rep.h" +#include "Rep.h" #include @@ -28,32 +28,33 @@ struct GadgetSet { // methods void update(); - void render(RenderInfo * info); + void render(RenderInfo* info); void invalidateRep(cRep_t type, cRepInv_t level); - PyMOLGlobals *G; - ObjectGadget* Obj = nullptr; /* NOT pickled -- restore manually */ - int State = 0; /* NOT pickled -- restore manually */ - float *Coord = nullptr; - float *Normal = nullptr; - float *Color = nullptr; + PyMOLGlobals* G; + ObjectGadget* Obj = nullptr; /* NOT pickled -- restore manually */ + int State = 0; /* NOT pickled -- restore manually */ + float* Coord = nullptr; + float* Normal = nullptr; + float* Color = nullptr; int NCoord = 0; int NNormal = 0; int NColor = 0; - CGO *PickShapeCGO = nullptr; - CGO *PickCGO = nullptr; - CGO *StdCGO = nullptr; - CGO *ShapeCGO = nullptr; + CGO* PickShapeCGO = nullptr; + CGO* PickCGO = nullptr; + CGO* StdCGO = nullptr; + CGO* ShapeCGO = nullptr; int offsetPtOP = 0; int offsetPtOPick = 0; }; -GadgetSet *GadgetSetNew(PyMOLGlobals * G); -PyObject *GadgetSetAsPyList(GadgetSet * I, bool incl_cgos); -int GadgetSetFromPyList(PyMOLGlobals * G, PyObject * list, GadgetSet ** cs, int version); -int GadgetSetGetExtent(GadgetSet * I, float *mn, float *mx); -int GadgetSetGetVertex(const GadgetSet * I, int index, int base, float *v); -int GadgetSetSetVertex(GadgetSet * I, int index, int base, const float *v); +GadgetSet* GadgetSetNew(PyMOLGlobals* G); +PyObject* GadgetSetAsPyList(GadgetSet* I, bool incl_cgos); +int GadgetSetFromPyList( + PyMOLGlobals* G, PyObject* list, GadgetSet** cs, int version); +int GadgetSetGetExtent(GadgetSet* I, float* mn, float* mx); +int GadgetSetGetVertex(const GadgetSet* I, int index, int base, float* v); +int GadgetSetSetVertex(GadgetSet* I, int index, int base, const float* v); std::vector GadgetSetGetCoord(const GadgetSet* I); #endif diff --git a/layer2/ObjectGadget.cpp b/layer2/ObjectGadget.cpp index ed2f90757..67d408427 100644 --- a/layer2/ObjectGadget.cpp +++ b/layer2/ObjectGadget.cpp @@ -1,99 +1,135 @@ -/* +/* A* ------------------------------------------------------------------- B* This file contains source code for the PyMOL computer program -C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. +C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. D* ------------------------------------------------------------------- E* It is unlawful to modify or remove this copyright notice. F* ------------------------------------------------------------------- -G* Please see the accompanying LICENSE file for further information. +G* Please see the accompanying LICENSE file for further information. H* ------------------------------------------------------------------- I* Additional authors of this source file include: --* --* +-* +-* -* Z* ------------------------------------------------------------------- */ -#include"os_python.h" +#include "os_python.h" -#include"os_predef.h" -#include"os_std.h" -#include"os_gl.h" +#include "os_gl.h" +#include "os_predef.h" +#include "os_std.h" -#include"ObjectGadget.h" -#include"ObjectGadgetRamp.h" -#include"GadgetSet.h" -#include"Base.h" -#include"MemoryDebug.h" -#include"CGO.h" -#include"Scene.h" -#include"Setting.h" -#include"PConv.h" -#include"main.h" -#include"Color.h" -#include"VFont.h" +#include "Base.h" +#include "CGO.h" +#include "Color.h" +#include "GadgetSet.h" +#include "MemoryDebug.h" +#include "ObjectGadget.h" +#include "ObjectGadgetRamp.h" +#include "PConv.h" +#include "Scene.h" +#include "Setting.h" +#include "VFont.h" +#include "main.h" -CGO *ObjectGadgetPyListFloatToCGO(PyObject * list); +CGO* ObjectGadgetPyListFloatToCGO(PyObject* list); -int ObjectGadgetGetVertex(const ObjectGadget * I, int index, int base, float *v) +int ObjectGadgetGetVertex(const ObjectGadget* I, int index, int base, float* v) { - GadgetSet *gs; + GadgetSet* gs; int ok = false; - if(I->CurGSet < I->NGSet) { + if (I->CurGSet < I->NGSet) { gs = I->GSet[I->CurGSet]; - if(gs) { + if (gs) { ok = GadgetSetGetVertex(gs, index, base, v); } } return (ok); } -int ObjectGadgetSetVertex(ObjectGadget * I, int index, int base, const float *v) +int ObjectGadgetSetVertex(ObjectGadget* I, int index, int base, const float* v) { - GadgetSet *gs; + GadgetSet* gs; int ok = false; - if(I->CurGSet < I->NGSet) { + if (I->CurGSet < I->NGSet) { gs = I->GSet[I->CurGSet]; - if(gs) { + if (gs) { ok = GadgetSetSetVertex(gs, index, base, v); } } - if (index) // if 0 - xyz doesn't change, 1 - mouse position when changing colors + if (index) // if 0 - xyz doesn't change, 1 - mouse position when changing + // colors I->Changed = true; return (ok); } - /* in current state */ -ObjectGadget *ObjectGadgetTest(PyMOLGlobals * G) +ObjectGadget* ObjectGadgetTest(PyMOLGlobals* G) { - ObjectGadget *I = nullptr; - GadgetSet *gs = nullptr; - CGO *cgo = nullptr; + ObjectGadget* I = nullptr; + GadgetSet* gs = nullptr; + CGO* cgo = nullptr; int a; float coord[] = { - 0.5F, 0.5F, 0.0F, - 0.0F, 0.0F, 0.0F, - 0.3F, 0.0F, 0.0F, - 0.0F, -0.3F, 0.0F, - 0.3F, -0.3F, 0.0F, - 0.03F, -0.03F, 0.03F, - 0.27F, -0.03F, 0.03F, - 0.03F, -0.27F, 0.03F, - 0.27F, -0.27F, 0.03F, - 0.02F, -0.02F, 0.01F, - 0.28F, -0.02F, 0.01F, - 0.02F, -0.28F, 0.01F, - 0.28F, -0.28F, 0.01F, + 0.5F, + 0.5F, + 0.0F, + 0.0F, + 0.0F, + 0.0F, + 0.3F, + 0.0F, + 0.0F, + 0.0F, + -0.3F, + 0.0F, + 0.3F, + -0.3F, + 0.0F, + 0.03F, + -0.03F, + 0.03F, + 0.27F, + -0.03F, + 0.03F, + 0.03F, + -0.27F, + 0.03F, + 0.27F, + -0.27F, + 0.03F, + 0.02F, + -0.02F, + 0.01F, + 0.28F, + -0.02F, + 0.01F, + 0.02F, + -0.28F, + 0.01F, + 0.28F, + -0.28F, + 0.01F, }; float normal[] = { - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0, - -1.0, 0.0, 0.0, - 0.0, -1.0, 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 1.0, + -1.0, + 0.0, + 0.0, + 0.0, + -1.0, + 0.0, }; I = new ObjectGadget(G); @@ -101,13 +137,13 @@ ObjectGadget *ObjectGadgetTest(PyMOLGlobals * G) gs->NCoord = 13; gs->Coord = VLAlloc(float, gs->NCoord * 3); - for(a = 0; a < gs->NCoord * 3; a++) { + for (a = 0; a < gs->NCoord * 3; a++) { gs->Coord[a] = coord[a]; } gs->NNormal = 5; gs->Normal = VLAlloc(float, gs->NNormal * 3); - for(a = 0; a < gs->NNormal * 3; a++) { + for (a = 0; a < gs->NNormal * 3; a++) { gs->Normal[a] = normal[a]; } @@ -230,60 +266,59 @@ ObjectGadget *ObjectGadgetTest(PyMOLGlobals * G) gs->update(); ObjectGadgetUpdateExtents(I); return (I); - } -void ObjectGadgetUpdateExtents(ObjectGadget * I) +void ObjectGadgetUpdateExtents(ObjectGadget* I) { - float maxv[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; - float minv[3] = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; + float maxv[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; + float minv[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; int a; - GadgetSet *ds; + GadgetSet* ds; /* update extents */ copy3f(maxv, I->ExtentMin); copy3f(minv, I->ExtentMax); I->ExtentFlag = false; - for(a = 0; a < I->NGSet; a++) { + for (a = 0; a < I->NGSet; a++) { ds = I->GSet[a]; - if(ds) { - if(GadgetSetGetExtent(ds, I->ExtentMin, I->ExtentMax)) + if (ds) { + if (GadgetSetGetExtent(ds, I->ExtentMin, I->ExtentMax)) I->ExtentFlag = true; } } } -static PyObject *ObjectGadgetGSetAsPyList(ObjectGadget * I, bool incl_cgos) +static PyObject* ObjectGadgetGSetAsPyList(ObjectGadget* I, bool incl_cgos) { - PyObject *result = nullptr; + PyObject* result = nullptr; int a; result = PyList_New(I->NGSet); - for(a = 0; a < I->NGSet; a++) { - if(I->GSet[a]) { + for (a = 0; a < I->NGSet; a++) { + if (I->GSet[a]) { PyList_SetItem(result, a, GadgetSetAsPyList(I->GSet[a], incl_cgos)); } else { PyList_SetItem(result, a, PConvAutoNone(Py_None)); } } return (PConvAutoNone(result)); - } -static int ObjectGadgetGSetFromPyList(ObjectGadget * I, PyObject * list, int version) +static int ObjectGadgetGSetFromPyList( + ObjectGadget* I, PyObject* list, int version) { int ok = true; int a; - if(ok) + if (ok) ok = PyList_Check(list); - if(ok) { - VLACheck(I->GSet, GadgetSet *, I->NGSet); - for(a = 0; a < I->NGSet; a++) { - if(ok){ - auto *val = PyList_GetItem(list, a); + if (ok) { + VLACheck(I->GSet, GadgetSet*, I->NGSet); + for (a = 0; a < I->NGSet; a++) { + if (ok) { + auto* val = PyList_GetItem(list, a); ok = GadgetSetFromPyList(I->G, val, &I->GSet[a], version); } - if(ok && I->GSet[a]) { + if (ok && I->GSet[a]) { I->GSet[a]->Obj = I; I->GSet[a]->State = a; } @@ -292,31 +327,31 @@ static int ObjectGadgetGSetFromPyList(ObjectGadget * I, PyObject * list, int ver return (ok); } -int ObjectGadgetInitFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadget * I, - int version) +int ObjectGadgetInitFromPyList( + PyMOLGlobals* G, PyObject* list, ObjectGadget* I, int version) { int ok = true; - if(ok) + if (ok) ok = (I != nullptr) && (list != nullptr); - if(ok) + if (ok) ok = PyList_Check(list); /* TO SUPPORT BACKWARDS COMPATIBILITY... Always check ll when adding new PyList_GetItem's */ - if(ok){ - auto *val = PyList_GetItem(list, 0); + if (ok) { + auto* val = PyList_GetItem(list, 0); ok = ObjectFromPyList(G, val, I); } - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 1), &I->GadgetType); - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 2), &I->NGSet); - if(ok) + if (ok) ok = ObjectGadgetGSetFromPyList(I, PyList_GetItem(list, 3), version); - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 4), &I->CurGSet); /* ObjectGadgetInvalidateRep(I,cRepAll); */ - if(ok) { + if (ok) { ObjectGadgetUpdateExtents(I); } else { /* cleanup? */ @@ -324,41 +359,42 @@ int ObjectGadgetInitFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadget * return (ok); } -int ObjectGadgetNewFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadget ** result, - int version) +int ObjectGadgetNewFromPyList( + PyMOLGlobals* G, PyObject* list, ObjectGadget** result, int version) { int ok = true; - ObjectGadget *I = nullptr; + ObjectGadget* I = nullptr; int gadget_type = -1; - PyObject *plain; + PyObject* plain; (*result) = nullptr; - if(ok) + if (ok) ok = (list != nullptr); - if(ok) + if (ok) ok = PyList_Check(list); - /* NOTE there is a serious screw-up here...ramp gadgets aren't saved right, but - we've got to maintain backward compat...ugh */ + /* NOTE there is a serious screw-up here...ramp gadgets aren't saved right, + but we've got to maintain backward compat...ugh */ - if(ok) + if (ok) ok = ((plain = PyList_GetItem(list, 0)) != nullptr); - if(ok) + if (ok) ok = PyList_Check(plain); - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(plain, 1), &gadget_type); - if(ok) - switch (gadget_type) { /* call the right routine to restore the gadget! */ + if (ok) + switch (gadget_type) { /* call the right routine to restore the gadget! */ case cGadgetRamp: - ok = ObjectGadgetRampNewFromPyList(G, list, (ObjectGadgetRamp **) result, version); + ok = ObjectGadgetRampNewFromPyList( + G, list, (ObjectGadgetRamp**) result, version); break; case cGadgetPlain: I = new ObjectGadget(G); - if(ok) + if (ok) ok = (I != nullptr); - if(ok) + if (ok) ok = ObjectGadgetInitFromPyList(G, list, I, version); - if(ok) + if (ok) (*result) = I; break; default: @@ -368,9 +404,9 @@ int ObjectGadgetNewFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadget ** return (ok); } -PyObject *ObjectGadgetPlainAsPyList(ObjectGadget * I, bool incl_cgos) +PyObject* ObjectGadgetPlainAsPyList(ObjectGadget* I, bool incl_cgos) { - PyObject *result = nullptr; + PyObject* result = nullptr; /* first, dump the atoms */ @@ -383,15 +419,15 @@ PyObject *ObjectGadgetPlainAsPyList(ObjectGadget * I, bool incl_cgos) return (PConvAutoNone(result)); } -PyObject *ObjectGadgetAsPyList(ObjectGadget * I) +PyObject* ObjectGadgetAsPyList(ObjectGadget* I) { - PyObject *result = nullptr; + PyObject* result = nullptr; /* first, dump the atoms */ switch (I->GadgetType) { case cGadgetRamp: - result = ObjectGadgetRampAsPyList((ObjectGadgetRamp *) I); + result = ObjectGadgetRampAsPyList((ObjectGadgetRamp*) I); break; case cGadgetPlain: result = ObjectGadgetPlainAsPyList(I); @@ -403,38 +439,37 @@ PyObject *ObjectGadgetAsPyList(ObjectGadget * I) ObjectGadget::~ObjectGadget() { auto I = this; - for(int a = 0; a < I->NGSet; a++) - if(I->GSet[a]) { + for (int a = 0; a < I->NGSet; a++) + if (I->GSet[a]) { delete I->GSet[a]; I->GSet[a] = nullptr; } } -void ObjectGadgetUpdateStates(ObjectGadget * I) +void ObjectGadgetUpdateStates(ObjectGadget* I) { int a; OrthoBusyPrime(I->G); - for(a = 0; a < I->NGSet; a++) - if(I->GSet[a]) { + for (a = 0; a < I->NGSet; a++) + if (I->GSet[a]) { OrthoBusySlow(I->G, a, I->NGSet); - /* printf(" ObjectGadget: updating state %d of \"%s\".\n" , a+1, I->Name); */ + /* printf(" ObjectGadget: updating state %d of \"%s\".\n" , a+1, + * I->Name); */ I->GSet[a]->update(); } } - /*========================================================================*/ void ObjectGadget::update() { auto I = this; - if(I->Changed) { + if (I->Changed) { ObjectGadgetUpdateStates(I); ObjectGadgetUpdateExtents(I); I->Changed = false; } } - /*========================================================================*/ int ObjectGadget::getNFrame() const @@ -442,34 +477,32 @@ int ObjectGadget::getNFrame() const return NGSet; } - /*========================================================================*/ -void ObjectGadget::render(RenderInfo * info) +void ObjectGadget::render(RenderInfo* info) { auto I = this; int state = info->state; const RenderPass pass = info->pass; - if(pass == RenderPass::Transparent || info->ray || info->pick) { + if (pass == RenderPass::Transparent || info->ray || info->pick) { ObjectPrepareContext(I, info); - for(StateIterator iter(I->G, I->Setting.get(), state, I->NGSet); + for (StateIterator iter(I->G, I->Setting.get(), state, I->NGSet); iter.next();) { - GadgetSet * gs = I->GSet[iter.state]; + GadgetSet* gs = I->GSet[iter.state]; gs->render(info); } } } - /*========================================================================*/ -ObjectGadget::ObjectGadget(PyMOLGlobals * G) : pymol::CObject(G) +ObjectGadget::ObjectGadget(PyMOLGlobals* G) + : pymol::CObject(G) { type = cObjectGadget; - GSet = pymol::vla(10); /* auto-zero */ + GSet = pymol::vla(10); /* auto-zero */ } pymol::RenderContext ObjectGadget::getRenderContext() const { return pymol::RenderContext::UnitWindow; } - diff --git a/layer2/ObjectGadget.h b/layer2/ObjectGadget.h index 80b69237f..7b3bffe55 100644 --- a/layer2/ObjectGadget.h +++ b/layer2/ObjectGadget.h @@ -1,28 +1,28 @@ -/* +/* A* ------------------------------------------------------------------- B* This file contains source code for the PyMOL computer program -C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. +C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. D* ------------------------------------------------------------------- E* It is unlawful to modify or remove this copyright notice. F* ------------------------------------------------------------------- -G* Please see the accompanying LICENSE file for further information. +G* Please see the accompanying LICENSE file for further information. H* ------------------------------------------------------------------- I* Additional authors of this source file include: --* --* +-* +-* -* Z* ------------------------------------------------------------------- */ #ifndef _H_ObjectGadget #define _H_ObjectGadget -#include"os_python.h" +#include "os_python.h" -#include"PyMOLObject.h" -#include"Base.h" +#include "Base.h" +#include "PyMOLObject.h" -#include"GadgetSet.h" +#include "GadgetSet.h" struct ObjectGadget : public pymol::CObject { pymol::vla GSet; @@ -43,18 +43,20 @@ struct ObjectGadget : public pymol::CObject { #define cGadgetPlain 0 #define cGadgetRamp 1 -PyObject *ObjectGadgetAsPyList(ObjectGadget * I); -PyObject *ObjectGadgetPlainAsPyList(ObjectGadget * I, bool incl_cgos=true); +PyObject* ObjectGadgetAsPyList(ObjectGadget* I); +PyObject* ObjectGadgetPlainAsPyList(ObjectGadget* I, bool incl_cgos = true); -int ObjectGadgetNewFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadget ** result, - int version); -int ObjectGadgetInitFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadget * I, - int version); +int ObjectGadgetNewFromPyList( + PyMOLGlobals* G, PyObject* list, ObjectGadget** result, int version); +int ObjectGadgetInitFromPyList( + PyMOLGlobals* G, PyObject* list, ObjectGadget* I, int version); -ObjectGadget *ObjectGadgetTest(PyMOLGlobals * G); -int ObjectGadgetGetVertex(const ObjectGadget * I, int index, int base, float *v); /* in current state */ -int ObjectGadgetSetVertex(ObjectGadget * I, int index, int base, const float *v); /* in current state */ -void ObjectGadgetUpdateExtents(ObjectGadget * I); -void ObjectGadgetUpdateStates(ObjectGadget * I); +ObjectGadget* ObjectGadgetTest(PyMOLGlobals* G); +int ObjectGadgetGetVertex(const ObjectGadget* I, int index, int base, + float* v); /* in current state */ +int ObjectGadgetSetVertex(ObjectGadget* I, int index, int base, + const float* v); /* in current state */ +void ObjectGadgetUpdateExtents(ObjectGadget* I); +void ObjectGadgetUpdateStates(ObjectGadget* I); #endif diff --git a/layer2/ObjectGadgetRamp.cpp b/layer2/ObjectGadgetRamp.cpp index e91787178..6cfc079a8 100644 --- a/layer2/ObjectGadgetRamp.cpp +++ b/layer2/ObjectGadgetRamp.cpp @@ -1,45 +1,45 @@ -/* +/* A* ------------------------------------------------------------------- B* This file contains source code for the PyMOL computer program -C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. +C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. D* ------------------------------------------------------------------- E* It is unlawful to modify or remove this copyright notice. F* ------------------------------------------------------------------- -G* Please see the accompanying LICENSE file for further information. +G* Please see the accompanying LICENSE file for further information. H* ------------------------------------------------------------------- I* Additional authors of this source file include: --* --* +-* +-* -* Z* ------------------------------------------------------------------- */ -#include"os_python.h" +#include "os_python.h" -#include"os_predef.h" -#include"os_std.h" -#include"os_gl.h" +#include "os_gl.h" +#include "os_predef.h" +#include "os_std.h" -#include"ObjectGadgetRamp.h" -#include"GadgetSet.h" -#include"Base.h" -#include"MemoryDebug.h" -#include"CGO.h" -#include"Scene.h" -#include"Setting.h" -#include"PConv.h" -#include"main.h" -#include"Color.h" -#include"VFont.h" -#include"ObjectMolecule.h" -#include"Executive.h" -#include"Util.h" -#include"P.h" -#include"PyMOLObject.h" +#include "Base.h" +#include "CGO.h" +#include "Color.h" +#include "Executive.h" #include "Feedback.h" +#include "GadgetSet.h" +#include "MemoryDebug.h" +#include "ObjectGadgetRamp.h" +#include "ObjectMolecule.h" +#include "P.h" +#include "PConv.h" +#include "PyMOLObject.h" +#include "Scene.h" +#include "Setting.h" +#include "Util.h" +#include "VFont.h" +#include "main.h" -static void ObjectGadgetRampBuild(ObjectGadgetRamp *); -static int ObjectGadgetRampHandleInputColors(ObjectGadgetRamp *); +static void ObjectGadgetRampBuild(ObjectGadgetRamp*); +static int ObjectGadgetRampHandleInputColors(ObjectGadgetRamp*); ObjectGadgetRamp::~ObjectGadgetRamp() { @@ -47,16 +47,17 @@ ObjectGadgetRamp::~ObjectGadgetRamp() ColorForgetExt(I->G, I->Name); } -static void ObjectGadgetRampCalculate(ObjectGadgetRamp * I, float v, float *result) +static void ObjectGadgetRampCalculate( + ObjectGadgetRamp* I, float v, float* result) { const float _1 = 1.0F; const float _0 = 0.0F; /* from Filipe Maia */ /* All of this functions are taken right of the gnuplot manual */ - if(v > _1) + if (v > _1) v = _1; - else if(v < _0) + else if (v < _0) v = _0; switch (I->CalcMode) { @@ -83,7 +84,7 @@ static void ObjectGadgetRampCalculate(ObjectGadgetRamp * I, float v, float *resu case cRAMP_GRAYABLE: result[0] = v / 0.32F - 0.78125F; result[1] = 2 * v - 0.84F; - result[2] = v / 0.08F - 11.5F; /* I'm not so sure about this one */ + result[2] = v / 0.08F - 11.5F; /* I'm not so sure about this one */ break; case cRAMP_RAINBOW: result[0] = (float) fabs(2 * v - 0.5F); @@ -100,7 +101,7 @@ static void ObjectGadgetRampCalculate(ObjectGadgetRamp * I, float v, float *resu result[1] = v; result[2] = v; break; - default: /* default is simply white */ + default: /* default is simply white */ result[0] = 1.0F; result[1] = 1.0F; result[2] = 1.0F; @@ -112,7 +113,8 @@ static void ObjectGadgetRampCalculate(ObjectGadgetRamp * I, float v, float *resu /** * Get the "Level" array, eventually spaced out to match number of colors. */ -static const float * ObjectGadgetRampGetLevel(ObjectGadgetRamp * I) { +static const float* ObjectGadgetRampGetLevel(ObjectGadgetRamp* I) +{ if (!I->Level || !I->Color) return I->Level; @@ -135,72 +137,74 @@ static const float * ObjectGadgetRampGetLevel(ObjectGadgetRamp * I) { /** * We support storing special color indices as negative R in the RGB color */ -inline int GetSpecial(const float * rgb) { +inline int GetSpecial(const float* rgb) +{ if (rgb[0] < 0.f) return (int) rgb[0]; return 0; } -static int _ObjectGadgetRampInterpolate(ObjectGadgetRamp * I, float level, float *color, - const float *table) +static int _ObjectGadgetRampInterpolate( + ObjectGadgetRamp* I, float level, float* color, const float* table) { - const float *i_level = ObjectGadgetRampGetLevel(I); + const float* i_level = ObjectGadgetRampGetLevel(I); int n_level = VLAGetSize(i_level); const float _0 = 0.0F; const float _1 = 1.0F; int ok = true; - if(i_level && table) { + if (i_level && table) { int level_is_ge = -1; int level_is_le = n_level; int i = 0; i = n_level - 1; - while(i >= 0) { + while (i >= 0) { float f = i_level[i]; - if(level >= f) { + if (level >= f) { level_is_ge = i; break; } i--; } i = 0; - while(i < n_level) { + while (i < n_level) { float f = i_level[i]; - if(level <= f) { + if (level <= f) { level_is_le = i; break; } else i++; } - if(level_is_ge != level_is_le) { - if(level_is_le == 0) { /* lower extreme */ + if (level_is_ge != level_is_le) { + if (level_is_le == 0) { /* lower extreme */ copy3f(table, color); - } else if(level_is_ge == (n_level - 1)) { /* upper extreme */ + } else if (level_is_ge == (n_level - 1)) { /* upper extreme */ copy3f(table + 3 * (n_level - 1), color); } else { float d, x0, x1; d = i_level[level_is_ge] - i_level[level_is_le]; - if(fabs(d) > R_SMALL8) { + if (fabs(d) > R_SMALL8) { x0 = (level - i_level[level_is_le]) / d; x1 = 1.0F - x0; - for(i = 0; i < 3; i++) { - color[i] = x0 * table[3 * level_is_ge + i] + x1 * table[3 * level_is_le + i]; + for (i = 0; i < 3; i++) { + color[i] = x0 * table[3 * level_is_ge + i] + + x1 * table[3 * level_is_le + i]; } clamp3f(color); } else { copy3f(table + 3 * level_is_ge, color); } } - } else { /* dead on the specified level */ + } else { /* dead on the specified level */ copy3f(table + 3 * level_is_ge, color); clamp3f(color); } } else { float base, range; - if(n_level && i_level) { + if (n_level && i_level) { base = i_level[0]; range = i_level[n_level - 1] - base; - if(fabs(range) < R_SMALL8) + if (fabs(range) < R_SMALL8) range = _1; } else { base = _0; @@ -212,12 +216,12 @@ static int _ObjectGadgetRampInterpolate(ObjectGadgetRamp * I, float level, float return (ok); } -static int _ObjectGadgetRampBlend(ObjectGadgetRamp * I, float *color, - const float *table, int mode) +static int _ObjectGadgetRampBlend( + ObjectGadgetRamp* I, float* color, const float* table, int mode) { /* this capability needs to be re-thought */ - const float *i_level = ObjectGadgetRampGetLevel(I); + const float* i_level = ObjectGadgetRampGetLevel(I); int n_level = VLAGetSize(i_level); const float _1 = 1.0F; float avg[3]; @@ -231,13 +235,13 @@ static int _ObjectGadgetRampBlend(ObjectGadgetRamp * I, float *color, case 2: break; default: - if(i_level && table) { + if (i_level && table) { int i; - for(i = 0; i < n_level; i++) { + for (i = 0; i < n_level; i++) { add3f(table + 3 * i, avg, avg); cnt++; } - if(cnt) { + if (cnt) { float fact = _1 / cnt; scale3f(avg, fact, avg); } @@ -248,38 +252,40 @@ static int _ObjectGadgetRampBlend(ObjectGadgetRamp * I, float *color, } switch (mode) { - case 1: /* min components */ + case 1: /* min components */ case 3: ones3f(color); - if(i_level && table) { + if (i_level && table) { int i, j; - for(i = 0; i < n_level; i++) { - for(j = 0; j < 3; j++) { - color[j] = (color[j] < table[3 * i + j]) ? color[j] : table[3 * i + j]; + for (i = 0; i < n_level; i++) { + for (j = 0; j < 3; j++) { + color[j] = + (color[j] < table[3 * i + j]) ? color[j] : table[3 * i + j]; } } clamp3f(color); } - if(mode == 3) { /* average serves as a minimum */ + if (mode == 3) { /* average serves as a minimum */ int j; - for(j = 0; j < 3; j++) { + for (j = 0; j < 3; j++) { color[j] = (color[j] > avg[j]) ? color[j] : avg[j]; } } break; - case 2: /* max components */ + case 2: /* max components */ zero3f(color); - if(i_level && table) { + if (i_level && table) { int i, j; - for(i = 0; i < n_level; i++) { - for(j = 0; j < 3; j++) { - color[j] = (color[j] > table[3 * i + j]) ? color[j] : table[3 * i + j]; + for (i = 0; i < n_level; i++) { + for (j = 0; j < 3; j++) { + color[j] = + (color[j] > table[3 * i + j]) ? color[j] : table[3 * i + j]; } } clamp3f(color); } break; - default: /* simple average of all colors */ + default: /* simple average of all colors */ copy3f(avg, color); break; } @@ -288,43 +294,40 @@ static int _ObjectGadgetRampBlend(ObjectGadgetRamp * I, float *color, #define MAX_COLORS 64 -static int ObjectGadgetRampInterpolateWithSpecial(ObjectGadgetRamp * I, - float level, - float *color, - const float *atomic, - const float *object, - const float *vertex, int state, int blend_all) +static int ObjectGadgetRampInterpolateWithSpecial(ObjectGadgetRamp* I, + float level, float* color, const float* atomic, const float* object, + const float* vertex, int state, int blend_all) { /* now thread-safe...via stack copy of colors */ float stack_color[MAX_COLORS * 3]; - const float *i_level = ObjectGadgetRampGetLevel(I); - const float *i_color = I->Color; + const float* i_level = ObjectGadgetRampGetLevel(I); + const float* i_color = I->Color; - if(i_level && i_color) { + if (i_level && i_color) { int i = 0; int n_level = VLAGetSize(i_level); /* mix special coloring into the table */ - const float *src = i_color; - float *dst = stack_color; - if((n_level + 2) > MAX_COLORS) + const float* src = i_color; + float* dst = stack_color; + if ((n_level + 2) > MAX_COLORS) n_level = MAX_COLORS - 2; - while(i < n_level) { + while (i < n_level) { int index = GetSpecial(src); switch (index) { - case 0: - copy3f(src, dst); - break; - case cColorDefault: - case cColorAtomic: - copy3f(atomic, dst); - break; - case cColorObject: - copy3f(object, dst); - break; - default: /* allow nested ramps */ - ColorGetRamped(I->G, index, vertex, dst, state); - break; + case 0: + copy3f(src, dst); + break; + case cColorDefault: + case cColorAtomic: + copy3f(atomic, dst); + break; + case cColorObject: + copy3f(object, dst); + break; + default: /* allow nested ramps */ + ColorGetRamped(I->G, index, vertex, dst, state); + break; } dst += 3; src += 3; @@ -334,32 +337,32 @@ static int ObjectGadgetRampInterpolateWithSpecial(ObjectGadgetRamp * I, } /* interpolate using static tables */ - if(blend_all) + if (blend_all) return _ObjectGadgetRampBlend(I, color, i_color, I->SrcState); return _ObjectGadgetRampInterpolate(I, level, color, i_color); } -int ObjectGadgetRampInterpolate(ObjectGadgetRamp * I, float level, float *color) +int ObjectGadgetRampInterpolate(ObjectGadgetRamp* I, float level, float* color) { int result = _ObjectGadgetRampInterpolate(I, level, color, I->Color); return result; } -PyObject *ObjectGadgetRampAsPyList(ObjectGadgetRamp * I) +PyObject* ObjectGadgetRampAsPyList(ObjectGadgetRamp* I) { - PyObject *result = nullptr; + PyObject* result = nullptr; result = PyList_New(11); PyList_SetItem(result, 0, ObjectGadgetPlainAsPyList(I, false)); PyList_SetItem(result, 1, PyInt_FromLong(I->RampType)); PyList_SetItem(result, 2, PyInt_FromLong(I->NLevel)); - if(I->Level && I->NLevel) { + if (I->Level && I->NLevel) { PyList_SetItem(result, 3, PConvFloatVLAToPyList(I->Level)); } else { PyList_SetItem(result, 3, PConvAutoNone(nullptr)); } - if(I->Color && I->NLevel) { + if (I->Color && I->NLevel) { PyList_SetItem(result, 4, PConvFloatVLAToPyList(I->Color)); } else { PyList_SetItem(result, 4, PConvAutoNone(nullptr)); @@ -372,71 +375,75 @@ PyObject *ObjectGadgetRampAsPyList(ObjectGadgetRamp * I) // I->Special, removed in PyMOL 1.8 bool any = false; int* special = nullptr; - int pse_export_version = SettingGetGlobal_f(I->G, cSetting_pse_export_version) * 1000; + int pse_export_version = + SettingGetGlobal_f(I->G, cSetting_pse_export_version) * 1000; if (I->Color && pse_export_version < 1800) { int n_color = VLAGetSize(I->Color) / 3; special = VLAlloc(int, n_color); for (int a = 0; a < n_color; ++a) { any = (special[a] = GetSpecial(I->Color + a * 3)) || any; + } } - } - PyList_SetItem(result, 9, any ? PConvIntVLAToPyList(special) : PConvAutoNone(nullptr)); + PyList_SetItem( + result, 9, any ? PConvIntVLAToPyList(special) : PConvAutoNone(nullptr)); VLAFreeP(special); - PyList_SetItem(result, 10, PConvAutoNone(nullptr) /* I->Extreme, removed in PyMOL 1.8 */); + PyList_SetItem(result, 10, + PConvAutoNone(nullptr) /* I->Extreme, removed in PyMOL 1.8 */); return (PConvAutoNone(result)); } -int ObjectGadgetRampNewFromPyList(PyMOLGlobals * G, PyObject * list, - ObjectGadgetRamp ** result, int version) +int ObjectGadgetRampNewFromPyList( + PyMOLGlobals* G, PyObject* list, ObjectGadgetRamp** result, int version) { - ObjectGadgetRamp *I = nullptr; + ObjectGadgetRamp* I = nullptr; int ok = true; int ll = 0; - if(ok) + if (ok) I = new ObjectGadgetRamp(G); - if(ok) + if (ok) ok = (I != nullptr); - if(ok) + if (ok) ok = (list != nullptr); - if(ok) + if (ok) ok = PyList_Check(list); - if(ok) + if (ok) ll = PyList_Size(list); /* TO SUPPORT BACKWARDS COMPATIBILITY... Always check ll when adding new PyList_GetItem's */ - if(ok){ + if (ok) { auto val = PyList_GetItem(list, 0); ok = ObjectGadgetInitFromPyList(G, val, I, version); } - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 1), &I->RampType); - if(ok) + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 2), &I->NLevel); - if(ok && I->NLevel) + if (ok && I->NLevel) ok = PConvPyListToFloatVLA(PyList_GetItem(list, 3), &I->Level); - if(ok && I->NLevel) { - PyObject *item = PyList_GetItem(list, 4); - if(item != Py_None) { + if (ok && I->NLevel) { + PyObject* item = PyList_GetItem(list, 4); + if (item != Py_None) { ok = PConvPyListToFloatVLA(item, &I->Color); } } - if(ok) - ok = CPythonVal_PConvPyStrToStr_From_List(G, list, 6, I->SrcName, WordLength); - if(ok) + if (ok) + ok = CPythonVal_PConvPyStrToStr_From_List( + G, list, 6, I->SrcName, WordLength); + if (ok) ok = PConvPyIntToInt(PyList_GetItem(list, 7), &I->SrcState); - if(ok && (ll > 8)) + if (ok && (ll > 8)) ok = CPythonVal_PConvPyIntToInt_From_List(G, list, 8, &I->CalcMode); - if(ok && I->NLevel && (ll > 10)) { - CPythonVal *item = CPythonVal_PyList_GetItem(G, list, 10); - if(!CPythonVal_IsNone(item)) { + if (ok && I->NLevel && (ll > 10)) { + CPythonVal* item = CPythonVal_PyList_GetItem(G, list, 10); + if (!CPythonVal_IsNone(item)) { // ObjectGadgetRamp::Extreme removed in PyMOL 1.8 // Copy extreme colors to the beginning and end of the Color array // and repeat the first and last level value - float *extreme = nullptr; + float* extreme = nullptr; PConvPyListToFloatVLA(item, &extreme); if (extreme) { I->NLevel += 2; @@ -462,102 +469,102 @@ int ObjectGadgetRampNewFromPyList(PyMOLGlobals * G, PyObject * list, ObjectGadgetRampHandleInputColors(I); ObjectGadgetRampBuild(I); - if(ok) + if (ok) (*result) = I; return (ok); } -int ObjectGadgetRampInterVertex(ObjectGadgetRamp * I, const float *pos, float *color, int state) +int ObjectGadgetRampInterVertex( + ObjectGadgetRamp* I, const float* pos, float* color, int state) { float level; int ok = true; switch (I->RampType) { case cRampMap: - if(!I->Map) + if (!I->Map) I->Map = ExecutiveFindObjectMapByName(I->G, I->SrcName); - if(!ExecutiveValidateObjectPtr(I->G, I->Map, cObjectMap)) + if (!ExecutiveValidateObjectPtr(I->G, I->Map, cObjectMap)) ok = false; else { int src_state; - if(I->SrcState >= 0) + if (I->SrcState >= 0) src_state = I->SrcState; else src_state = state; - if(src_state < 0) + if (src_state < 0) src_state = SceneGetState(I->G); - if(ok) + if (ok) ok = (I->Map != nullptr); - if(ok) + if (ok) ok = ObjectMapInterpolate(I->Map, src_state, pos, &level, nullptr, 1); - if(ok) + if (ok) ok = ObjectGadgetRampInterpolate(I, level, color); } break; case cRampMol: - if(!I->Mol) + if (!I->Mol) I->Mol = ExecutiveFindObjectMoleculeByName(I->G, I->SrcName); - if(!ExecutiveValidateObjectPtr(I->G, I->Mol, cObjectMolecule)) + if (!ExecutiveValidateObjectPtr(I->G, I->Mol, cObjectMolecule)) ok = false; else { float cutoff = 1.0F; float dist; int sub_vdw = false; - if(state < 0) + if (state < 0) state = SceneGetState(I->G); - if(I->Level && I->NLevel) { + if (I->Level && I->NLevel) { cutoff = I->Level[I->NLevel - 1]; - if(I->Level[0] < 0.0F) { + if (I->Level[0] < 0.0F) { sub_vdw = true; cutoff += MAX_VDW; } } - if(ok) + if (ok) ok = (I->Mol != nullptr); - if(ok) { - if (I->Mol->NCSet==1) // if only one state, then set state to 0 - state = 0; - if(SettingGet_b - (I->G, I->Setting.get(), nullptr, - cSetting_ramp_blend_nearby_colors)) { + if (ok) { + if (I->Mol->NCSet == 1) // if only one state, then set state to 0 + state = 0; + if (SettingGet_b(I->G, I->Setting.get(), nullptr, + cSetting_ramp_blend_nearby_colors)) { float atomic[3]; - int index = - ObjectMoleculeGetNearestBlendedColor(I->Mol, pos, cutoff, state, &dist, - atomic, sub_vdw); - if(index >= 0) { - const float *object = ColorGetRaw(I->G, I->Mol->Color); + int index = ObjectMoleculeGetNearestBlendedColor( + I->Mol, pos, cutoff, state, &dist, atomic, sub_vdw); + if (index >= 0) { + const float* object = ColorGetRaw(I->G, I->Mol->Color); - if(!ObjectGadgetRampInterpolateWithSpecial(I, dist, color, atomic, - object, pos, state, false)) { + if (!ObjectGadgetRampInterpolateWithSpecial( + I, dist, color, atomic, object, pos, state, false)) { copy3f(I->Color.data(), color); } } else { - float white[3] = { 1.0F, 1.0F, 1.0F }; - if(!ObjectGadgetRampInterpolateWithSpecial(I, cutoff + 1.0F, color, white, - white, pos, state, false)) { + float white[3] = {1.0F, 1.0F, 1.0F}; + if (!ObjectGadgetRampInterpolateWithSpecial( + I, cutoff + 1.0F, color, white, white, pos, state, false)) { copy3f(I->Color.data(), color); } } } else { - int index = - ObjectMoleculeGetNearestAtomIndex(I->Mol, pos, cutoff, state, &dist); - if(index >= 0) { - const float *atomic = ColorGetRaw(I->G, I->Mol->AtomInfo[index].color); - const float *object = ColorGetRaw(I->G, I->Mol->Color); + int index = ObjectMoleculeGetNearestAtomIndex( + I->Mol, pos, cutoff, state, &dist); + if (index >= 0) { + const float* atomic = + ColorGetRaw(I->G, I->Mol->AtomInfo[index].color); + const float* object = ColorGetRaw(I->G, I->Mol->Color); - if(sub_vdw) { + if (sub_vdw) { dist -= I->Mol->AtomInfo[index].vdw; - if(dist < 0.0F) + if (dist < 0.0F) dist = 0.0F; } - if(!ObjectGadgetRampInterpolateWithSpecial(I, dist, color, atomic, - object, pos, state, false)) { + if (!ObjectGadgetRampInterpolateWithSpecial( + I, dist, color, atomic, object, pos, state, false)) { copy3f(I->Color.data(), color); } } else { - float white[3] = { 1.0F, 1.0F, 1.0F }; - if(!ObjectGadgetRampInterpolateWithSpecial(I, cutoff + 1.0F, color, white, - white, pos, state, false)) { + float white[3] = {1.0F, 1.0F, 1.0F}; + if (!ObjectGadgetRampInterpolateWithSpecial( + I, cutoff + 1.0F, color, white, white, pos, state, false)) { copy3f(I->Color.data(), color); } } @@ -565,14 +572,13 @@ int ObjectGadgetRampInterVertex(ObjectGadgetRamp * I, const float *pos, float *c } } break; - case cRampNone: - { - float white[3] = { 1.0F, 1.0F, 1.0F }; - if(!ObjectGadgetRampInterpolateWithSpecial(I, 0.0F, color, white, white, pos, state, true)) { /* simple blend */ - copy3f(I->Color.data(), color); - } + case cRampNone: { + float white[3] = {1.0F, 1.0F, 1.0F}; + if (!ObjectGadgetRampInterpolateWithSpecial(I, 0.0F, color, white, white, + pos, state, true)) { /* simple blend */ + copy3f(I->Color.data(), color); } - break; + } break; default: ok = false; break; @@ -580,9 +586,9 @@ int ObjectGadgetRampInterVertex(ObjectGadgetRamp * I, const float *pos, float *c return (ok); } -static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) +static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp* I, GadgetSet* gs) { - CGO *cgo; + CGO* cgo; int a; char buffer[255]; int blocked = false; @@ -591,7 +597,7 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) blocked = PAutoBlock(I->G); font_id = VFontLoad(I->G, 1.0, 1, 1, true); - if(blocked) + if (blocked) PUnblock(I->G); cgo = CGONewSized(I->G, 100); @@ -601,24 +607,23 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) CGOColor(cgo, 0.05F, 0.05F, 0.05F); CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 CGOVertex(cgo, I->border, -(I->border + I->bar_height), I->border); // 9 - CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 - CGOVertex(cgo, I->width + I->border, -(I->border + I->bar_height), I->border); // 10 - CGOVertex(cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 + CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 + CGOVertex( + cgo, I->width + I->border, -(I->border + I->bar_height), I->border); // 10 + CGOVertex( + cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 CGOEnd(cgo); - CGOColor(cgo, 1.0F, 1.0F, 1.0F); - CGONormal(cgo, 0.f, 0.f, 1.f); // text/characters need z-normal to include normals in vbo - if(I->Level && I->NLevel) { + CGONormal(cgo, 0.f, 0.f, + 1.f); // text/characters need z-normal to include normals in vbo + if (I->Level && I->NLevel) { float exindent = (n_color > 0) ? I->bar_height : 0.f; - float pos[] = { I->border + I->text_border + exindent, - I->text_border - (I->border + I->height), - I->border + I->text_raise }; - float scale[] = { I->text_scale_h, I->text_scale_v }; - float axes[] = { 1.0F, 0.0F, 0.0F, - 0.0F, 1.0F, 0.0F, - 0.0F, 0.0F, 1.0F }; - float color[] = { 1.f, 1.f, 1.f }; + float pos[] = {I->border + I->text_border + exindent, + I->text_border - (I->border + I->height), I->border + I->text_raise}; + float scale[] = {I->text_scale_h, I->text_scale_v}; + float axes[] = {1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F}; + float color[] = {1.f, 1.f, 1.f}; /* left text for ramp */ sprintf(buffer, "%0.3f", I->Level[0]); VFontWriteToCGO(I->G, font_id, cgo, buffer, pos, scale, axes, color); @@ -626,7 +631,7 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) /* right text, right justified for ramp */ pos[0] = I->width + I->border - exindent; pos[1] = I->text_border - (I->border + I->height); - pos[2] = I->border + I->text_raise ; + pos[2] = I->border + I->text_raise; sprintf(buffer, "%0.3f", I->Level[I->NLevel - 1]); /* indent for right justification */ VFontIndent(I->G, font_id, buffer, pos, scale, axes, -1.f); @@ -636,12 +641,12 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) /* center */ CGOBegin(cgo, GL_TRIANGLE_STRIP); CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 - if(n_color > 0) { - const float *i_level = ObjectGadgetRampGetLevel(I); - const float *src = I->Color; + if (n_color > 0) { + const float* i_level = ObjectGadgetRampGetLevel(I); + const float* src = I->Color; float stack_color[6], stack_level[2] = {0.f, 1.f}; - if(n_color == 1) { + if (n_color == 1) { n_color = 2; copy3f(src, stack_color); copy3f(src, stack_color + 3); @@ -665,11 +670,11 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) } // repeat first and last color in a `bar_height` wide square - for(a = -1; a <= n_color; a++) { + for (a = -1; a <= n_color; a++) { float tmp[3] = {1.f, 1.f, 1.f}; float v1 = I->border; - if(!GetSpecial(src)) { + if (!GetSpecial(src)) { copy3f(src, tmp); ColorLookupColor(I->G, tmp); } @@ -677,14 +682,15 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) if (a == n_color) { v1 += I->width; } else if (a != -1) { - v1 += I->bar_height + (I->width - 2 * I->bar_height) * (i_level[a] - i_level[0]) / range; + v1 += I->bar_height + (I->width - 2 * I->bar_height) * + (i_level[a] - i_level[0]) / range; if (a != n_color - 1) { src += 3; } } CGOColorv(cgo, tmp); - CGOVertex(cgo, v1, -I->border, I->border); + CGOVertex(cgo, v1, -I->border, I->border); CGOVertex(cgo, v1, -I->border - I->bar_height, I->border); } } else { @@ -692,14 +698,15 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) float fxn; float color[3]; - for(a = 0; a < samples; a++) { + for (a = 0; a < samples; a++) { fxn = a / (samples - 1.0F); ObjectGadgetRampCalculate(I, fxn, color); CGOColorv(cgo, color); CGOVertex(cgo, I->border + (I->width * fxn), -I->border, I->border); - CGOVertex(cgo, I->border + (I->width * fxn), -(I->border + I->bar_height), I->border); + CGOVertex(cgo, I->border + (I->width * fxn), -(I->border + I->bar_height), + I->border); } } /* center */ @@ -710,51 +717,55 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) /* top */ CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 - CGOVertex(cgo, I->border, -I->border, I->border); // 5 + CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 + CGOVertex(cgo, I->border, -I->border, I->border); // 5 CGOVertex(cgo, I->width + I->border, -I->border, I->border); // 6 - CGONormal(cgo, 0.f, 1.f, .1f); // normal 1 - CGOVertex(cgo, 0.0, 0.0, 0.0); // 1 - CGOVertex(cgo, I->width + I->border * 2, 0.0, 0.0); // 2 + CGONormal(cgo, 0.f, 1.f, .1f); // normal 1 + CGOVertex(cgo, 0.0, 0.0, 0.0); // 1 + CGOVertex(cgo, I->width + I->border * 2, 0.0, 0.0); // 2 CGOEnd(cgo); /* bottom */ CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGONormal(cgo, 0.f, -1.f, .1f); // normal 4 + CGONormal(cgo, 0.f, -1.f, .1f); // normal 4 CGOVertex(cgo, 0.f, -(I->height + I->border * 2), 0.f); // 3 - CGOVertex(cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 - CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 + CGOVertex( + cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 + CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 - CGOVertex(cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 + CGOVertex( + cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 CGOEnd(cgo); /* left */ CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGONormal(cgo, -1.f, 0.f, 0.1f); // normal 3 - CGOVertex(cgo, 0.f, 0.f, 0.f); // 1 - CGOVertex(cgo, 0.f, -(I->height + I->border * 2), 0.f); // 3 - CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 - CGOVertex(cgo, I->border, -I->border, I->border); // 5 + CGONormal(cgo, -1.f, 0.f, 0.1f); // normal 3 + CGOVertex(cgo, 0.f, 0.f, 0.f); // 1 + CGOVertex(cgo, 0.f, -(I->height + I->border * 2), 0.f); // 3 + CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 + CGOVertex(cgo, I->border, -I->border, I->border); // 5 CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 CGOEnd(cgo); /* right */ CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 + CGONormal(cgo, 0.f, 0.f, 1.f); // normal 2 CGOVertex(cgo, I->width + I->border, -I->border, I->border); // 6 - CGOVertex(cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 - CGONormal(cgo, 1.f, 0.f, .1f); // normal 0 + CGOVertex( + cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 + CGONormal(cgo, 1.f, 0.f, .1f); // normal 0 CGOVertex(cgo, I->width + I->border * 2, 0.f, 0.f); // 2 - CGOVertex(cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 + CGOVertex( + cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 CGOEnd(cgo); CGOStop(cgo); CGOFree(gs->ShapeCGO); gs->ShapeCGO = cgo; - //#ifndef _PYMOL_NOPY + // #ifndef _PYMOL_NOPY CGOPreloadFonts(gs->ShapeCGO); - //#endif + // #endif cgo = CGONewSized(I->G, 100); CGODotwidth(cgo, 5); @@ -762,43 +773,48 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) /* top */ CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGOVertex(cgo, 0.f, 0.f, 0.f); // 1 - CGOVertex(cgo, I->width + I->border * 2, 0.f, 0.f); // 2 - CGOVertex(cgo, I->border, -I->border, I->border); // 5 + CGOVertex(cgo, 0.f, 0.f, 0.f); // 1 + CGOVertex(cgo, I->width + I->border * 2, 0.f, 0.f); // 2 + CGOVertex(cgo, I->border, -I->border, I->border); // 5 CGOVertex(cgo, I->width + I->border, -I->border, I->border); // 6 CGOEnd(cgo); /* bottom */ CGOBegin(cgo, GL_TRIANGLE_STRIP); CGOVertex(cgo, 0.f, -(I->height + I->border * 2), 0.f); // 3 - CGOVertex(cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 - CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 - CGOVertex(cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 + CGOVertex( + cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 + CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 + CGOVertex( + cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 CGOEnd(cgo); /* left */ CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGOVertex(cgo, 0.f, 0.f, 0.f); // 1 - CGOVertex(cgo, 0.f, -(I->height + I->border * 2), 0.f); // 3 - CGOVertex(cgo, I->border, -I->border, I->border); // 5 + CGOVertex(cgo, 0.f, 0.f, 0.f); // 1 + CGOVertex(cgo, 0.f, -(I->height + I->border * 2), 0.f); // 3 + CGOVertex(cgo, I->border, -I->border, I->border); // 5 CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 CGOEnd(cgo); /* right */ CGOBegin(cgo, GL_TRIANGLE_STRIP); CGOVertex(cgo, I->width + I->border, -I->border, I->border); // 6 - CGOVertex(cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 - CGOVertex(cgo, I->width + I->border * 2, 0.f, 0.f); // 2 - CGOVertex(cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 + CGOVertex( + cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 + CGOVertex(cgo, I->width + I->border * 2, 0.f, 0.f); // 2 + CGOVertex( + cgo, I->width + I->border * 2, -(I->height + I->border * 2), 0.f); // 4 CGOEnd(cgo); /* band */ CGOPickColor(cgo, 1, cPickableGadget); CGOBegin(cgo, GL_TRIANGLE_STRIP); - CGOVertex(cgo, I->border, -I->border, I->border); // 5 - CGOVertex(cgo, I->width + I->border, -I->border, I->border); // 6 + CGOVertex(cgo, I->border, -I->border, I->border); // 5 + CGOVertex(cgo, I->width + I->border, -I->border, I->border); // 6 CGOVertex(cgo, I->border, -(I->height + I->border), I->border); // 7 - CGOVertex(cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 + CGOVertex( + cgo, I->width + I->border, -(I->height + I->border), I->border); // 8 CGOEnd(cgo); CGOStop(cgo); @@ -807,10 +823,10 @@ static void ObjectGadgetRampUpdateCGO(ObjectGadgetRamp * I, GadgetSet * gs) gs->PickShapeCGO = cgo; } -static void ObjectGadgetRampBuild(ObjectGadgetRamp * I) +static void ObjectGadgetRampBuild(ObjectGadgetRamp* I) { - GadgetSet *gs = nullptr; - ObjectGadget *og; + GadgetSet* gs = nullptr; + ObjectGadget* og; OrthoBusyPrime(I->G); @@ -836,36 +852,32 @@ static void ObjectGadgetRampBuild(ObjectGadgetRamp * I) og->GSet[0] = gs; og->NGSet = 1; - gs->Obj = (ObjectGadget *) I; + gs->Obj = (ObjectGadget*) I; gs->State = 0; ObjectGadgetRampUpdateCGO(I, gs); gs->update(); - } - /*========================================================================*/ void ObjectGadgetRamp::update() { auto I = this; float scale; - if(I->Changed) { + if (I->Changed) { scale = (1.0F + 5 * I->GSet[0]->Coord[1 * 3]); I->GSet[0]->Coord[1 * 3] = 0.0; switch (I->RampType) { - case cRampMol: - { - int a; - for(a = 0; a < I->NLevel; a++) { - I->Level[a] = I->Level[a] * scale; - } - ExecutiveInvalidateRep(I->G, cKeywordAll, cRepAll, cRepInvColor); + case cRampMol: { + int a; + for (a = 0; a < I->NLevel; a++) { + I->Level[a] = I->Level[a] * scale; } - break; + ExecutiveInvalidateRep(I->G, cKeywordAll, cRepAll, cRepInvColor); + } break; default: - if(I->NLevel == 2) { + if (I->NLevel == 2) { { float mean = (I->Level[0] + I->Level[1]) / 2.0F; I->Level[0] = (I->Level[0] - mean) * scale + mean; @@ -873,15 +885,15 @@ void ObjectGadgetRamp::update() ExecutiveInvalidateRep(I->G, cKeywordAll, cRepAll, cRepInvColor); } break; - } else if(I->NLevel == 3) { + } else if (I->NLevel == 3) { I->Level[0] = (I->Level[0] - I->Level[1]) * scale + I->Level[1]; I->Level[2] = (I->Level[2] - I->Level[1]) * scale + I->Level[1]; ExecutiveInvalidateRep(I->G, cKeywordAll, cRepAll, cRepInvColor); } } VLAFreeP(I->LevelTmp); - if(I->NGSet) - if(I->GSet[0]) { + if (I->NGSet) + if (I->GSet[0]) { ObjectGadgetRampUpdateCGO(I, I->GSet[0]); ObjectGadgetUpdateStates(I); } @@ -891,36 +903,38 @@ void ObjectGadgetRamp::update() } } -static int ObjectGadgetRampHandleInputColors(ObjectGadgetRamp * I) +static int ObjectGadgetRampHandleInputColors(ObjectGadgetRamp* I) { VLAFreeP(I->LevelTmp); - if(I->NLevel < 1) { + if (I->NLevel < 1) { VLASize(I->Level, float, 1); I->NLevel = 1; I->Level[0] = 0.0F; } - if(I->Color) { + if (I->Color) { int n_color = VLAGetSize(I->Color) / 3; /* handle cases where number of colors doesn't make expectation */ - if(!n_color) { + if (!n_color) { VLASize(I->Color, float, 3); I->Color[0] = I->Color[1] = I->Color[2] = 1.0F; n_color++; } - if(n_color != I->NLevel && I->NLevel != 2) { + if (n_color != I->NLevel && I->NLevel != 2) { PRINTFB(I->G, FB_ObjectGadget, FB_Warnings) - " GadgetRamp-Warning: number of colors (%d) and number of levels (%d) don't\n" - " match and n_level != 2. Support for trailing extreme colors dropped in 1.8.", - n_color, I->NLevel ENDFB(I->G); + " GadgetRamp-Warning: number of colors (%d) and number of levels (%d) " + "don't\n" + " match and n_level != 2. Support for trailing extreme colors dropped in " + "1.8.", + n_color, I->NLevel ENDFB(I->G); } - if(n_color < I->NLevel) { + if (n_color < I->NLevel) { // repeat last color until n_color == NLevel VLASize(I->Color, float, 3 * I->NLevel); - while(n_color < I->NLevel) { + while (n_color < I->NLevel) { copy3f(I->Color + 3 * (n_color - 1), I->Color + 3 * n_color); n_color++; } @@ -930,17 +944,11 @@ static int ObjectGadgetRampHandleInputColors(ObjectGadgetRamp * I) return true; } - /*========================================================================*/ -ObjectGadgetRamp *ObjectGadgetRampMapNewAsDefined(PyMOLGlobals * G, - ObjectGadgetRamp *I, - ObjectMap * map, - pymol::vla&& level_vla, - pymol::vla&& color_vla, - int map_state, - float *vert_vla, float beyond, - float within, float sigma, int zero, - int calc_mode) +ObjectGadgetRamp* ObjectGadgetRampMapNewAsDefined(PyMOLGlobals* G, + ObjectGadgetRamp* I, ObjectMap* map, pymol::vla&& level_vla, + pymol::vla&& color_vla, int map_state, float* vert_vla, float beyond, + float within, float sigma, int zero, int calc_mode) { if (!I) I = new ObjectGadgetRamp(G); @@ -953,19 +961,20 @@ ObjectGadgetRamp *ObjectGadgetRampMapNewAsDefined(PyMOLGlobals * G, } { - ObjectMapState *ms; + ObjectMapState* ms; float tmp_level[3]; - if(map_state < 0) + if (map_state < 0) map_state = 0; - if(vert_vla && map && (ms = ObjectMapGetState(map, map_state))) { - if(ObjectMapStateGetExcludedStats(G, ms, vert_vla, beyond, within, tmp_level)) { + if (vert_vla && map && (ms = ObjectMapGetState(map, map_state))) { + if (ObjectMapStateGetExcludedStats( + G, ms, vert_vla, beyond, within, tmp_level)) { tmp_level[0] = tmp_level[1] + (tmp_level[0] - tmp_level[1]) * sigma; tmp_level[2] = tmp_level[1] + (tmp_level[2] - tmp_level[1]) * sigma; - if(zero) { - if(tmp_level[1] < 0.0F) { + if (zero) { + if (tmp_level[1] < 0.0F) { tmp_level[1] = 0.0F; tmp_level[2] = -tmp_level[0]; - } else if(tmp_level[1] > 0.0F) { + } else if (tmp_level[1] > 0.0F) { tmp_level[1] = 0.0F; tmp_level[0] = -tmp_level[2]; } @@ -979,7 +988,7 @@ ObjectGadgetRamp *ObjectGadgetRampMapNewAsDefined(PyMOLGlobals * G, } } - I->NLevel = VLAGetSize(I->Level); + I->NLevel = VLAGetSize(I->Level); ObjectGadgetRampHandleInputColors(I); ObjectGadgetRampBuild(I); @@ -990,17 +999,12 @@ ObjectGadgetRamp *ObjectGadgetRampMapNewAsDefined(PyMOLGlobals * G, } return (I); - } - /*========================================================================*/ -ObjectGadgetRamp *ObjectGadgetRampMolNewAsDefined(PyMOLGlobals * G, - ObjectGadgetRamp *I, - ObjectMolecule * mol, - pymol::vla&& level_vla, - pymol::vla&& color_vla, - int mol_state, int calc_mode) +ObjectGadgetRamp* ObjectGadgetRampMolNewAsDefined(PyMOLGlobals* G, + ObjectGadgetRamp* I, ObjectMolecule* mol, pymol::vla&& level_vla, + pymol::vla&& color_vla, int mol_state, int calc_mode) { if (!I) { I = new ObjectGadgetRamp(G); @@ -1008,7 +1012,7 @@ ObjectGadgetRamp *ObjectGadgetRampMolNewAsDefined(PyMOLGlobals * G, UtilNCopy(I->SrcName, "none", WordLength); } - if(mol) { + if (mol) { I->RampType = cRampMol; I->Mol = mol; I->SrcState = mol_state; @@ -1020,7 +1024,7 @@ ObjectGadgetRamp *ObjectGadgetRampMolNewAsDefined(PyMOLGlobals * G, I->CalcMode = calc_mode; } - if(level_vla) { + if (level_vla) { I->Level = std::move(level_vla); I->NLevel = VLAGetSize(I->Level); } @@ -1030,14 +1034,11 @@ ObjectGadgetRamp *ObjectGadgetRampMolNewAsDefined(PyMOLGlobals * G, return (I); } -void ObjectGadgetRamp::invalidate(cRep_t rep, cRepInv_t level, - int state) -{ -} - +void ObjectGadgetRamp::invalidate(cRep_t rep, cRepInv_t level, int state) {} /*========================================================================*/ -ObjectGadgetRamp::ObjectGadgetRamp(PyMOLGlobals * G) : ObjectGadget(G) +ObjectGadgetRamp::ObjectGadgetRamp(PyMOLGlobals* G) + : ObjectGadget(G) { auto I = this; I->GadgetType = cGadgetRamp; diff --git a/layer2/ObjectGadgetRamp.h b/layer2/ObjectGadgetRamp.h index 0e7024eb1..1cbae5e21 100644 --- a/layer2/ObjectGadgetRamp.h +++ b/layer2/ObjectGadgetRamp.h @@ -1,23 +1,23 @@ -/* +/* A* ------------------------------------------------------------------- B* This file contains source code for the PyMOL computer program -C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. +C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. D* ------------------------------------------------------------------- E* It is unlawful to modify or remove this copyright notice. F* ------------------------------------------------------------------- -G* Please see the accompanying LICENSE file for further information. +G* Please see the accompanying LICENSE file for further information. H* ------------------------------------------------------------------- I* Additional authors of this source file include: --* --* +-* +-* -* Z* ------------------------------------------------------------------- */ #ifndef _H_ObjectGadgetRamp #define _H_ObjectGadgetRamp -#include"os_python.h" +#include "os_python.h" #include "ObjectGadget.h" @@ -45,8 +45,8 @@ struct ObjectGadgetRamp : public ObjectGadget { int CalcMode = 0; /* fields below are not saved in session */ - ObjectMap *Map = nullptr; - ObjectMolecule *Mol = nullptr; + ObjectMap* Map = nullptr; + ObjectMolecule* Mol = nullptr; float border = 0.018f; float width = 0.9f; @@ -75,29 +75,22 @@ struct ObjectGadgetRamp : public ObjectGadget { #define cRAMP_AFMHOT 7 #define cRAMP_GRAYSCALE 8 -ObjectGadgetRamp *ObjectGadgetRampMapNewAsDefined(PyMOLGlobals * G, - ObjectGadgetRamp *I, - ObjectMap * map, - pymol::vla&& level_vla, - pymol::vla&& color_vla, - int map_state, float *vert_vla, - float beyond, float within, float sigma, - int zero, int calc_mode); +ObjectGadgetRamp* ObjectGadgetRampMapNewAsDefined(PyMOLGlobals* G, + ObjectGadgetRamp* I, ObjectMap* map, pymol::vla&& level_vla, + pymol::vla&& color_vla, int map_state, float* vert_vla, float beyond, + float within, float sigma, int zero, int calc_mode); -ObjectGadgetRamp *ObjectGadgetRampMolNewAsDefined(PyMOLGlobals * G, - ObjectGadgetRamp *I, - ObjectMolecule * mol, - pymol::vla&& level_vla, - pymol::vla&& color_vla, - int mol_state, int calc_mode); +ObjectGadgetRamp* ObjectGadgetRampMolNewAsDefined(PyMOLGlobals* G, + ObjectGadgetRamp* I, ObjectMolecule* mol, pymol::vla&& level_vla, + pymol::vla&& color_vla, int mol_state, int calc_mode); -int ObjectGadgetRampInterpolate(ObjectGadgetRamp * I, float level, float *color); -int ObjectGadgetRampInterVertex(ObjectGadgetRamp * I, const float *pos, float *color, - int state); +int ObjectGadgetRampInterpolate(ObjectGadgetRamp* I, float level, float* color); +int ObjectGadgetRampInterVertex( + ObjectGadgetRamp* I, const float* pos, float* color, int state); -PyObject *ObjectGadgetRampAsPyList(ObjectGadgetRamp * I); -int ObjectGadgetRampNewFromPyList(PyMOLGlobals * G, PyObject * list, - ObjectGadgetRamp ** result, int version); +PyObject* ObjectGadgetRampAsPyList(ObjectGadgetRamp* I); +int ObjectGadgetRampNewFromPyList( + PyMOLGlobals* G, PyObject* list, ObjectGadgetRamp** result, int version); -void ObjectGadgetRampFree(ObjectGadgetRamp * I); +void ObjectGadgetRampFree(ObjectGadgetRamp* I); #endif