From 34b00130fa32c397fb604533fbc8df7ccbbcae62 Mon Sep 17 00:00:00 2001 From: toshinagata1964 Date: Tue, 26 Jun 2012 11:57:25 +0000 Subject: [PATCH] Molecule#is_atom_hidden and AtomRef#hidden, hidden= are implemented, and Molecule#hidden_atoms and hidden_atoms= are made obsolete. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@236 a2be9bc6-48de-4e38-9406-05402d4bc13c --- Documents/src/molby_rb/AtomRef.html | 15 ++++++++ Documents/src/molby_rb/Molecule.html | 45 ++++++++---------------- MolLib/Ruby_bind/ruby_bind.c | 67 ++++++++++++++++++++++++++++++++---- 3 files changed, 89 insertions(+), 38 deletions(-) diff --git a/Documents/src/molby_rb/AtomRef.html b/Documents/src/molby_rb/AtomRef.html index 6379112..311d07d 100644 --- a/Documents/src/molby_rb/AtomRef.html +++ b/Documents/src/molby_rb/AtomRef.html @@ -343,6 +343,21 @@ Get/set the fractional coordinate z. If the crystallographic unit cell is not de
+ +
+ +hidden → Boolean
+self.hidden = Boolean
+
+
+
+

+Get/set the hidden flag. This is an atom attribute, and is independent with the Molecule attribute such as Molecule#show_hydrogens, Molecule#show_dummy_atoms and Molecule#show_expanded. If you want to examine the visibility of an atom by taking these attributes into consideration, try Molecule#is_atom_visible. +

+
+
+ +
diff --git a/Documents/src/molby_rb/Molecule.html b/Documents/src/molby_rb/Molecule.html index c32b9a1..d7a7b84 100644 --- a/Documents/src/molby_rb/Molecule.html +++ b/Documents/src/molby_rb/Molecule.html @@ -1345,7 +1345,7 @@ Get the current rotation for the view. Angle is in degree, not radian. The sign

-Get the current scale for the view. Scale is expressed with a floating-point number in the range -5.0 to 5.0. The scale parameter is transformed to perspective parameters (fovy and distance) in the following way: for negative scale, fovy = 30 deg and distance = cot(15) * 10^(-scale); for positive scale, fovy = 30 * 10^(-scale) and distance = cot(15). +Get the current scale for the view. Scale is expressed with a dimensionless floating-point number in the range -5.0 to 5.0. The scale parameter is transformed to perspective parameters (fovy and distance) in the following way: for negative scale, fovy = 30 degree and distance = cot(15) * 10^(-scale) * 10 Å; for positive scale, fovy = 30 * 10^(-scale) degree and distance = cot(15) * 10 Å.

See Also: Molecule#set_view_scale @@ -1380,36 +1380,6 @@ Create bonds between atoms that are within the threshold distance. If limit is a

- -
-hidden_atoms → IntGroup -
-
-

-Returns a list of currently hidden atoms. -

-

-See Also: Molecule#hidden_atoms= -

-
- -
- -
-self.hidden_atoms = IntGroup
-set_hidden_atoms(IntGroup) -
-
-
-

-Hide the specified atoms. Note: this operation is _not_ undoable. -

-

-See Also: Molecule#hidden_atoms -

-
- -
hide_graphic(graphic_index) → self @@ -1510,6 +1480,19 @@ Invert the molecule with the given center. If group is given, only the atoms in
+
+ +
+is_atom_hidden(index) → Boolean
+
+
+
+

+Check whether the atom is visible or not. Unlike AtomRef#hidden, this method takes care of the Molecule attributes show_hydrogens, show_expanded and show_dummy_atoms. +

+
+
+
diff --git a/MolLib/Ruby_bind/ruby_bind.c b/MolLib/Ruby_bind/ruby_bind.c index f3de893..726aedf 100644 --- a/MolLib/Ruby_bind/ruby_bind.c +++ b/MolLib/Ruby_bind/ruby_bind.c @@ -69,7 +69,8 @@ static VALUE s_SigmaSym, s_SigmaXSym, s_SigmaYSym, s_SigmaZSym, s_VSym, s_FSym, s_OccupancySym, s_TempFactorSym, s_AnisoSym, s_SymopSym, s_IntChargeSym, s_FixForceSym, - s_FixPosSym, s_ExclusionSym, s_MMExcludeSym, s_PeriodicExcludeSym; + s_FixPosSym, s_ExclusionSym, s_MMExcludeSym, s_PeriodicExcludeSym, + s_HiddenSym; /* Symbols for parameter attributes */ static VALUE @@ -3482,6 +3483,10 @@ static VALUE s_AtomRef_GetPeriodicExclude(VALUE self) { return INT2NUM(s_AtomFromValue(self)->periodic_exclude); } +static VALUE s_AtomRef_GetHidden(VALUE self) { + return ((s_AtomFromValue(self)->exflags & kAtomHiddenFlag) != 0 ? Qtrue : Qfalse); +} + static VALUE s_AtomRef_SetIndex(VALUE self, VALUE val) { rb_raise(rb_eMolbyError, "index cannot be directly set"); return Qnil; @@ -3920,6 +3925,18 @@ static VALUE s_AtomRef_SetPeriodicExclude(VALUE self, VALUE val) { return val; } +static VALUE s_AtomRef_SetHidden(VALUE self, VALUE val) { + Atom *ap = s_AtomFromValue(self); + VALUE oval = ((ap->exflags & kAtomHiddenFlag) != 0 ? Qtrue : Qfalse); + if (RTEST(val)) { + ap->exflags |= kAtomHiddenFlag; + } else { + ap->exflags &= ~kAtomHiddenFlag; + } + s_RegisterUndoForAtomAttrChange(self, s_HiddenSym, val, oval); + return val; +} + static struct s_AtomAttrDef { char *name; VALUE *symref; /* Address of s_IndexSymbol etc. */ @@ -3963,6 +3980,7 @@ static struct s_AtomAttrDef { {"exclusion", &s_ExclusionSym, 0, s_AtomRef_GetExclusion, s_AtomRef_SetExclusion}, {"mm_exclude", &s_MMExcludeSym, 0, s_AtomRef_GetMMExclude, s_AtomRef_SetMMExclude}, {"periodic_exclude", &s_PeriodicExcludeSym, 0, s_AtomRef_GetPeriodicExclude, s_AtomRef_SetPeriodicExclude}, + {"hidden", &s_HiddenSym, 0, s_AtomRef_GetHidden, s_AtomRef_SetHidden}, {NULL} /* Sentinel */ }; @@ -6617,7 +6635,9 @@ s_Molecule_SetUndoableSelection(VALUE self, VALUE val) static VALUE s_Molecule_HiddenAtoms(VALUE self) { - Molecule *mol; + rb_raise(rb_eMolbyError, "set_hidden_atoms is now obsolete. Try using Molecule#is_atom_visible or AtomRef#hidden."); + return Qnil; /* Not reached */ +/* Molecule *mol; IntGroup *ig; VALUE val; Data_Get_Struct(self, Molecule, mol); @@ -6633,7 +6653,7 @@ s_Molecule_HiddenAtoms(VALUE self) IntGroupRelease(ig); rb_obj_freeze(val); return val; - } else return Qnil; + } else return Qnil; */ } /* @@ -6646,6 +6666,9 @@ s_Molecule_HiddenAtoms(VALUE self) static VALUE s_Molecule_SetHiddenAtoms(VALUE self, VALUE val) { + rb_raise(rb_eMolbyError, "set_hidden_atoms is now obsolete. Try using Molecule#is_atom_visible or AtomRef#hidden."); + return Qnil; /* Not reached */ +/* Molecule *mol; Data_Get_Struct(self, Molecule, mol); if (mol != NULL) { @@ -6667,7 +6690,7 @@ s_Molecule_SetHiddenAtoms(VALUE self, VALUE val) IntGroupRelease(ig); MoleculeCallback_notifyModification(mol, 0); } - return val; + return val; */ } /* @@ -8166,6 +8189,35 @@ s_Molecule_ShowEllipsoids(int argc, VALUE *argv, VALUE self) /* * call-seq: + * is_atom_visible(index) -> Boolean + * + * Check is an atom is visible. It examines the atom attribute (ap->exflags & kAtomHiddenFlag) + * as well as the molecule attributes (showHydrogens, etc.) + */ +static VALUE +s_Molecule_IsAtomVisible(VALUE self, VALUE ival) +{ + Molecule *mol; + Int idx; + Atom *ap; + Data_Get_Struct(self, Molecule, mol); + idx = s_Molecule_AtomIndexFromValue(mol, ival); + if (idx < 0 || idx >= mol->natoms) + return Qnil; + ap = ATOM_AT_INDEX(mol->atoms, idx); + if (mol->mview != NULL) { + if (mol->mview->showHydrogens == 0 && ap->atomicNumber == 1) + return Qfalse; + if (mol->mview->showExpandedAtoms == 0 && SYMOP_ALIVE(ap->symop)) + return Qfalse; + if (mol->mview->showDummyAtoms == 0 && ap->atomicNumber == 0) + return Qfalse; + } + return ((ap->exflags & kAtomHiddenFlag) != 0 ? Qfalse : Qtrue); +} + +/* + * call-seq: * show_graphite -> Integer * show_graphite = Integer * show_graphite = boolean @@ -9400,9 +9452,9 @@ Init_Molby(void) rb_define_method(rb_cMolecule, "selection", s_Molecule_Selection, 0); rb_define_method(rb_cMolecule, "selection=", s_Molecule_SetSelection, 1); rb_define_method(rb_cMolecule, "set_undoable_selection", s_Molecule_SetUndoableSelection, 1); - rb_define_method(rb_cMolecule, "hidden_atoms", s_Molecule_HiddenAtoms, 0); - rb_define_method(rb_cMolecule, "hidden_atoms=", s_Molecule_SetHiddenAtoms, 1); - rb_define_alias(rb_cMolecule, "set_hidden_atoms", "hidden_atoms="); + rb_define_method(rb_cMolecule, "hidden_atoms", s_Molecule_HiddenAtoms, 0); /* obsolete */ + rb_define_method(rb_cMolecule, "hidden_atoms=", s_Molecule_SetHiddenAtoms, 1); /* obsolete */ + rb_define_alias(rb_cMolecule, "set_hidden_atoms", "hidden_atoms="); /* obsolete */ rb_define_method(rb_cMolecule, "frame", s_Molecule_Frame, 0); rb_define_method(rb_cMolecule, "frame=", s_Molecule_SelectFrame, 1); rb_define_alias(rb_cMolecule, "select_frame", "frame="); @@ -9451,6 +9503,7 @@ Init_Molby(void) rb_define_method(rb_cMolecule, "show_dummy_atoms=", s_Molecule_ShowDummyAtoms, -1); rb_define_method(rb_cMolecule, "show_expanded", s_Molecule_ShowExpanded, -1); rb_define_method(rb_cMolecule, "show_expanded=", s_Molecule_ShowExpanded, -1); + rb_define_method(rb_cMolecule, "is_atom_visible", s_Molecule_IsAtomVisible, 1); rb_define_method(rb_cMolecule, "show_ellipsoids", s_Molecule_ShowEllipsoids, -1); rb_define_method(rb_cMolecule, "show_ellipsoids=", s_Molecule_ShowEllipsoids, -1); rb_define_method(rb_cMolecule, "show_graphite", s_Molecule_ShowGraphite, -1); -- 2.11.0