Preserve zoom factor in MarvinSketchForm?

User 1a8d11549a

02-04-2011 06:23:14

I use MarvinSketchForm to exchange chemical drawings with my application (like OLE). When I change the zoom factor of the sketch in MarvinSketchForm, e.g. due to a large structure, then close it to return to my application and later re-open MarvinSketchForm to re-edit the structure, the zoom factor is back to default and must be re-adjusted manually every time .


Therefore: Is there a way to get and set the zoom factor of the MarvinSketchForm dialog in order to restore the original one when re-opening the dialog? Tanks for your help.

ChemAxon bd13b5bd77

03-04-2011 08:46:56

It seems to me that it cannot be set. And the sketcher does not save the zoom either.


Forwarded the qiestion to Marvin team lead.

User 1a8d11549a

03-04-2011 13:57:05

Thanks. Possibly the contained MSketchpane.getScale and MSketchPane.setScale could be exposed in the future by the MarvinSketchForm? Just an idea ...

ChemAxon bd13b5bd77

03-04-2011 14:59:45

I checked that, and it does not affect the zom.

ChemAxon bd13b5bd77

05-04-2011 11:38:12

Sorry, it seems that I cannot get it saved however it can be set after each startup:


 



       protected override void OnActivated(EventArgs e) {
         base.OnActivated(e);
         var baseEditor = new ParentField<MarvinEditorControl>(this, "editor");
         var sketcher = new ParentField<chemaxon.marvin.beans.MSketchPane>(baseEditor.Value, "_content");
         sketcher.Value.setScale(2 * chemaxon.marvin.beans.MSketchPane.getDefaultScale());
      }


explanation:



You should use the same trick you did for saving settings in the OnClosing event (field helper class - ParentField https://www.chemaxon.com/forum/ftopic7400.html), you should choose an event which you are able to access the child control in.



If you have it then simply set the scale there. To me the scale as word is not so precise than zoom would be but you can find an appropriate setting for you I am sure.


Default scale on the sketcher can do a good job for you.


Scale has replaced the original setMag(nify) method, from now it is depricated and removed from the API.


User 1a8d11549a

05-04-2011 13:46:53

Thanks, this already is a very good start and works nicely. However my scenario is as follows: The user changes the scale factor in the Marvin dialog, transfers the sketch to my application via the OK button, and when re-editing the sketch opens at the same scale as before.


This means that there should be ways not only to set the sketch scale, which works fine now, but also to get the current one applied by the user in the Marvin dialog when it is closed. I tried using "sketcher.value.getScale()" in the OnFormClosing override, but at this stage the scale already seems to be reset back to the default value. Maybe there's a better suited override procedure, which allows to capture the current scale before it is reset to default when the Marvin dialog closes?

ChemAxon bd13b5bd77

05-04-2011 22:52:59

If I were you I would try out the Deactivate as it is in pair with Activate.


Obviously when youa re setting it, it should be done only once since Activate can be fired more than once.


These are workarounds, the best would be to have this scale/zoom saved along with other user settings.


 


I talked to the Marvin lead and he mentioend such a request had not arrived yet, and so far the scale was saved into the mrv molecule file only. They will prioritize the save for this setting in the user preferences as well.


 

User 1a8d11549a

06-04-2011 06:24:55

Using OnDeactivate, getScale unfortunately also returns the default scale value after interactive user scaling, as anything else I tried. Only when changing the scale via the code posted earlier in this thread via setScale, then getScale returns the resulting correct scale. I suspect that this is a bug in .getScale?


For explanation of my requirement: I am developing an electronic lab notebook, where obviously many different reaction skteches are present, some possibly drawn at a different scale than others. The sketch data are stored in a Marvin MoleculeString XML in a database. Whenever the user is coming back to re-edit a sktech, the MoleculeString is loaded into the editor dialog and should open at the scale it last time was edited and stored (much like when opening a .mrv file). This means that the application would retrieve and store the applied scale of each sketch separately and apply it whenever the MarvinSketch dialog opens for re-editing. In this sense future support for storing a global scale setting would be good, but the ability to retrieve an individual sketch scale, e.g. via .a working getScale function, even would be much better.

ChemAxon bd13b5bd77

06-04-2011 10:48:43

It works to me.


However you are partially right.


scenario:


sketch form default scale is 28.
set the scale to 2 * default = 56.
display the form zoom (200%)
manually I set it to 400% (the getscale expected to be 112)
close the form.
new form and settings the scale by saved getscale in deactivate, it is still 56 but not the original 28.


So getscale returns what you set but it was not refreshed by the gui!


So you are not fully right the sketchpane returns the actual value you set, but it is not updated from the gui dropdown! 


 

User 1a8d11549a

06-04-2011 11:51:38

So we seem to agree that the problem is that only the scale set by code (or the default if none was set) is returned, but any GUI scale changes are ignored. Are there any plans to fix this, since it still looks like a bug to me?

ChemAxon bd13b5bd77

06-04-2011 13:02:04

It seems our code was wrong, scale factor is a bounded property so it cannot work incorrectly.


Refined the "hack" solution, and it is working now. Activate/Deativate event is pretty frequent, we have to consider it when coding or workarounding.


 


      double? _scale = null;
      public double? Scale
      {
         get {
            return _scale;
         }
         set {
            _scale = value;
         }
      }
      private bool scaleSet = false;
      protected override void OnActivated(EventArgs e) {
         base.OnActivated(e);
         var baseEditor = new ParentField<MarvinEditorControl>(this, "editor");
         var sketcher = new ParentField<chemaxon.marvin.beans.MSketchPane>(baseEditor.Value, "_content");
         if (Scale != null) {
            if (!scaleSet) {
               sketcher.Value.setScale((double)Scale);
               scaleSet = true;
            }

         }
      }
      protected override void OnDeactivate(EventArgs e) {
         base.OnDeactivate(e);
         var baseEditor = new ParentField<MarvinEditorControl>(this, "editor");
         var sketcher = new ParentField<chemaxon.marvin.beans.MSketchPane>(baseEditor.Value, "_content");
         Scale = sketcher.Value.getScale();
      }


Explanation:


 


you have to flag that setting it should happen only once.


 


 

User 1a8d11549a

06-04-2011 13:47:12

Ok, I think we have it now. Your code initially didn't work for me, when no initial scale value was set in code. This fixed it for me (sorry for the VB.NEt):



Public 


Property Scale() As System.Nullable(Of Double)
   Get
      
If IsNothing(_scale) Then
          Return ChemAxon.marvin.beans.MSketchPane.getDefaultScale()
      Else
         Return _scale
      End If
    End Get
   Set(value As System.Nullable(Of Double))End Set
     _scale = value 
End
Property

Above code simply replaces no initial value by the explict default value, and then it works! So we have made it, thanks a lot Victor, thats all I needed.

User 1a8d11549a

08-04-2011 13:23:13

It seems that it's not so easy to get rid with me :-), but here's a hopefully last question for a long time, related to preserving settings: Coming from ISIS/Symyx/Accelrys Draw, I am used that the selection tool is the default tool when opening the editor. In MarvinSketch, however, the single bond tool is the default, so I (and maybe some others) are spending their time drawing some single bonds when trying to select something.


I am not asking to change the MarvinSketch default. But is there a way to programmatically select a tool towards being active when opening a MarvinSketchForm dialog, maybe even a sub-tool (Lasso, Rectangle, etc in case of the selection tool)? This currently would be my missing piece, otherwise everything works absolutely fine now (....we even have agreed on the general licensing terms yesterday :-)).

ChemAxon bd13b5bd77

08-04-2011 14:15:09

Before 5.5 version we have a limited access to the deafult tools:


http://www.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/beans/MSketchPane.html


http://www.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/beans/MSketchPane.html#setSketchMode(int)


setSketchMode is the API surface where you can amend the default tool. ( e.g. SM_SELECT_LASSO)


 


From 5.5, that will be released soon :


pane.setParam("defaultTool=lassoSelect"); will be avialable,


 


 

User 1a8d11549a

08-04-2011 14:54:58

Since MSketchPane isn't exposed by the MarvinSketchForm directly, I suppose you mean to usethe proposed functionality via our inofficial derived custom form? Anyway, doing so within the OnActivated override indeed works nicely, thanks a lot! - In this sense it would be a welcome addition, if MarvinSketchForm could expose its MSketchPane in the future (or did you mean this by your version 5.5 example?).

ChemAxon bd13b5bd77

08-04-2011 15:22:48

I think we are talking about 2 different things:


- what is exposed via the MarvinSketchForm


- what functionality is available via SketchPane


 


my answer was related to 2. what is avaialble on the sketch pane. Since I exposed the sketcher from the formto you , - which is pretty ugly now-, please interpret the sketch accessibility for the temp. solution. I do not emphaisize it in each answer.


based on your comments dotnet team will strengthen the 1. point.


Core team will strengthen the 2. point.


More flexible service in the 2. point will be available soon in 5.5., which means that you can go ahead with the "hack" to access the extended functionalities. In terms of 1. point we are going ahead and trying to extend the .net interfaces after 5.5, some minimal stuff are already built in from what you reported in 5.5.

User 1a8d11549a

08-04-2011 15:37:08

Ok, thanks for your clarification.