Example #1
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            if (ServiceFacade.ServiceFacade.InServiceCall)
            {
                return;                                                        // avoid multiplexing service calls that could cause problems
            }
            if (InTimer_Tick)
            {
                return;
            }
            InTimer_Tick = true;

            string currentCid = CidCtl.Text;

            if (currentCid == PreviousCid)
            {
                InTimer_Tick = false;
                return;
            }

            PreviousCid = currentCid;

            string     cid = CompoundId.Normalize(currentCid);
            MetaTable  mt  = CompoundId.GetRootMetaTableFromCid(cid);
            MoleculeMx mol = MoleculeUtil.SelectMoleculeForCid(cid, mt);

            QueryMolCtl.SetupAndRenderMolecule(mol);

            InTimer_Tick = false;
            return;
        }
Example #2
0
        private void AddToFavoritesButton_Click(object sender, EventArgs e)
        {
            Point p = RetrieveModel.PointToScreen(new System.Drawing.Point(0, AddToFavoritesButton.Height));

            MoleculeSelectorControl.AddToFavoritesList(QueryMolCtl, GetSearchType());
            QueryMolCtl.Focus();             // move focus away
        }
Example #3
0
 private void EditNewBiopolymerMenuItem_Click(object sender, EventArgs e)
 {
     QueryMolCtl.SetupAndEditNewMoleculeAsynch(MoleculeFormat.Helm);
 }
Example #4
0
 private void EditNewChemicalStructureMenuItem_Click(object sender, EventArgs e)
 {
     QueryMolCtl.SetupAndEditNewMoleculeAsynch(MoleculeFormat.Molfile);
 }
Example #5
0
 private void RetrieveFavoritesButton_Click(object sender, EventArgs e)
 {
     MoleculeSelectorControl.SelectFavoriteMolecule(QueryMolCtl);
     QueryMolCtl.Focus();             // move focus away
 }
Example #6
0
 private void NewBiopolymerMenuItem_Click(object sender, EventArgs e)
 {
     QueryMolCtl.Molecule = new MoleculeMx(MoleculeFormat.Helm);
     QueryMolCtl.RenderMolecule();
     DelayedCallback.Schedule(QueryMolCtl.EditMolecule);             // invoke editor after returning from this event
 }
Example #7
0
        /// <summary>
        /// Setup Form
        /// </summary>
        /// <param name="qc"></param>

        void SetupForm(
            QueryColumn qc)
        {
            bool enabled;

            SetupDepth++;

            Qc = qc;             // column we will be specifying criteria for

            // Setup dialog boxes with current settings

            Psc = ParsedStructureCriteria.Parse(Qc);

            // Enable Search option controls

            enabled           = ChemSearchIsSupportedForColumn;
            SubStruct.Enabled = Similarity.Enabled = Full.Enabled = enabled;
            if (Psc.SearchType == StructureSearchType.Unknown)             // default to SS search if not defined yet
            {
                Psc.SearchType = StructureSearchType.Substructure;
            }

            // Enable SmallWorld Search option controls

            enabled            = SmallWorldSearchIsSupportedForColumn;
            SmallWorld.Enabled = enabled;
            if (enabled)
            {
                if (Psc.SearchType == StructureSearchType.Unknown)                 // default to SmallWorld search
                {
                    Psc.SearchType = StructureSearchType.SmallWorld;
                }
            }
            else if (Psc.SearchType == StructureSearchType.SmallWorld)             // smallworld not allowed
            {
                Psc.SearchType = StructureSearchType.Unknown;
            }

            DisplayPreferences.SetStandardDisplayPreferences(QueryMolCtl.KekuleControl.Preferences);

            if (Psc.SearchType == StructureSearchType.Substructure)
            {
                SubStruct.Checked = true;
                QueryMolCtl.KekuleControl.Preferences.HydrogenDisplayMode = HydrogenDisplayMode.Off;                 // no hydrogen display for SSS
            }

            else if (Psc.SearchType == StructureSearchType.FullStructure)
            {
                Full.Checked = true;
            }

            else if (Psc.SearchType == StructureSearchType.MolSim)
            {
                Similarity.Checked = true;
            }

            else if (Psc.SearchType == StructureSearchType.SmallWorld)
            {
                SmallWorld.Checked = true;
            }

            else
            {
                None.Checked = true;
            }

            QueryMolCtl.SetupAndRenderMolecule(Psc.Molecule);

            QueryMolCtl.EditValueChanged += new System.EventHandler(QueryMolCtl_EditValueChanged);

            //SetMolDisplayFormatText();

            SetupOptions(true);
            SetupDepth--;

            return;
        }
Example #8
0
        /// <summary>
        /// Setup the form for display
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="qm"></param>
        /// <returns></returns>

        bool SetupForm(
            string cid,
            QueryManager qm)
        {
            AssertMx.IsDefined(cid, "Compound Id (CorpId)");

            SelectedCid = cid;
            PreviousCid = cid;

            RootTable = CompoundId.GetRootMetaTableFromCid(cid);

            Qm          = null;    // no query context
            SourceQuery = null;
            CurrentBaseQueryCidHitList = null;

            if (qm != null)             // if querymanager defined then base the related data query on the "current" query
            {
                Qm          = qm;       // setup query context
                SourceQuery = qm.Query;
                RootTable   = qm.Query.RootMetaTable;

                if (qm.Query != null && qm.Query.Mode == QueryMode.Browse)                 // if browsing current base query results then get that cid list
                {
                    CurrentBaseQueryCidHitList = Qm.DataTableManager.GetMostCompleteResultsKeyList();
                }
            }

            //else throw new Exception("Parameters not defined");

            //if (Lex.IsUndefined(SelectedCid) &&
            // (Qm == null || Qm.MoleculeGrid == null || Qm.MoleculeGrid.Helpers == null))
            //	return false;

            SetupCheckmarks();

            // Current Cid

            //if (Qm != null)
            //	SelectedCid = Qm.MoleculeGrid.Helpers.GetCidForSelectedCell();

            SelectedCid = CompoundId.Format(SelectedCid);
            CidCtl.Text = SelectedCid;
            //CidCtl.Focus();

            // Marked cid count

            MarkedCidsList = null;
            if (Qm?.MoleculeGrid != null)
            {
                CidList cl = Qm.MoleculeGrid.GetMarkedList();
                if (cl != null)
                {
                    MarkedCidsList = cl.ToStringList();
                }
            }

            int selCnt = (MarkedCidsList != null ? MarkedCidsList.Count : 0);

            MarkedCidsCheckEdit.Text    = "Selected compound Ids (" + FormatCidListForDisplay(MarkedCidsList) + ")";
            MarkedCidsCheckEdit.Enabled = (selCnt > 0);
            if (selCnt == 0 && MarkedCidsCheckEdit.Checked)
            {
                CurrentCidCheckEdit.Checked = true;
            }

            // All Cid count


            int allCnt = (CurrentBaseQueryCidHitList != null ? CurrentBaseQueryCidHitList.Count : 0);

            AllCidsCheckEdit.Text    = "All Ids in the current result set (" + FormatCidListForDisplay(CurrentBaseQueryCidHitList) + ")";
            AllCidsCheckEdit.Enabled = (allCnt > 0);
            if (selCnt == 0 && AllCidsCheckEdit.Checked)
            {
                CurrentCidCheckEdit.Checked = true;
            }

            // Structure

            MoleculeMx cs = new MoleculeMx();

            if (Lex.IsDefined(SelectedCid))
            {
                cs = MoleculeUtil.SelectMoleculeForCid(SelectedCid);
            }

            QueryMolCtl.SetupAndRenderMolecule(cs);

            // MRU list

            RenderMruList();

            return(true);
        }
Example #9
0
/// <summary>
/// Build the query
/// </summary>

        private Query BuildQuery()
        {
            Query        q, q2;
            QueryTable   qt;
            QueryColumn  keyQc;
            MetaTreeNode mtn;
            string       title = "";

            q = null;
            foreach (ImageListBoxItem item in MruListCtl.SelectedItems)
            {
                mtn = item.Tag as MetaTreeNode;

                if (mtn == null ||                 // use base query
                    (mtn.Type == MetaTreeNodeType.Query && Lex.Eq(mtn.Target, "RelatedCompoundsSourceQuery")))
                {
                    if (q == null)
                    {
                        q = SourceQuery.Clone();                         // base new query on query we originated from
                    }
                    else
                    {
                        q.MergeQuery(SourceQuery);
                    }
                }

                else if (mtn.Type == MetaTreeNodeType.Query)                 // selected query item
                {
                    UserObjectType objType;
                    int            objId = -1;

                    UserObject.ParseObjectTypeAndIdFromInternalName(mtn.Target, out objType, out objId);
                    q2 = QbUtil.QueriesControl.GetQueryByUserObjectId(objId);                     // if this query is open, get the current, possibly edited, version

                    if (q2 == null)
                    {
                        q2 = QbUtil.ReadQuery(mtn.Target);                         // read in existing query
                    }
                    if (q2 != null)
                    {
                        if (q == null)
                        {
                            q = q2.Clone();
                        }

                        else
                        {
                            q.MergeQuery(q2);
                        }
                    }
                }

                else if (mtn.IsDataTableType)                 // single data table
                {
                    MetaTable mt = MetaTableCollection.Get(mtn.Target);
                    if (mt == null)
                    {
                        throw new Exception("Can't get metatable " + mtn.Target);
                    }

                    if (q == null)
                    {
                        q = new Query();
                    }
                    if (Lex.IsUndefined(q.Name))
                    {
                        q.Name = mt.Label;
                    }
                    if (q.GetQueryTableByName(mt.Name) == null)                     // add table if not already included
                    {
                        qt = new QueryTable(q, mt);
                    }
                }

                else
                {
                    throw new Exception("Invalid node type: " + mtn.Type);
                }
            }

            List <string> cidList       = new List <string>();
            bool          cidBasedQuery = true;    // assume query is based on a list of cids

            string cid = CidCtl.Text;

            cid = CompoundId.Normalize(cid);

            // Retrieve data for a single Cid

            if (CurrentCidCheckEdit.Checked)
            {
                cidList.Add(cid);
                title = q.Name + " for " + RootTable.KeyMetaColumn.Label + " " + CidCtl.Text;
            }

// Retrieve data for related structures

            else if (RelatedStrsCheckEdit.Checked)
            {
                //	AltForms, MatchedPairs, SmallWorld, SimilarSearch, Substructure

                string queryStrName = QueryMolCtl.GetTemporaryStructureTag();
                if (Lex.IsUndefined(queryStrName))
                {
                    queryStrName = "query structure";
                }
                title         = q.Name + " compounds related to " + queryStrName;
                cidBasedQuery = false;                 // need to do a related structure search
            }

// Retrieve for marked Cids

            else if (MarkedCidsCheckEdit.Checked)
            {
                cidList = MarkedCidsList;
                title   = q.Name + " for checked " + RootTable.KeyMetaColumn.Label + "s";
            }

// Retrieve for all Cids in originating query

            else if (AllCidsCheckEdit.Checked)
            {
                cidList = CurrentBaseQueryCidHitList;
                title   = q.Name + " for current hitlist " + RootTable.KeyMetaColumn.Label + "s " + CidCtl.Text;
            }

            q.Name = title;             // name query same as title ( + " (Q" + (++QueryCount) + ")"; // with query sequence id appended)

            // Remove existing criteria if requested

            if (!ApplyExistingCriteria.Checked)
            {
                q.ClearAllQueryColumnCriteria();
            }

// Modify the derived query to do either a Cid or Related-structure search

            q.IncludeRootTableAsNeeded();
            if (IncludeStructures.Checked)
            {
                AddStructureTableToQuery(q);
            }

            if (cidBasedQuery)
            {
                ModifyQueryForCidSearch(q, cidList);
            }
            else
            {
                ModifyQueryForRelatedStructureSearch(q, QueryMolCtl);
            }

            q.SingleStepExecution = false;             // Single step fails for RelatedSS search (Done in QE now)

            return(q);
        }